Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Marta Miranda
/
boletin_api
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Enzo Yair
2023-07-30 17:58:15 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c841101aac781a6b523deee12e34bfd1d556683a
c841101a
1 parent
406b3315
se agregan_el_metodo_actualizar
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
15 deletions
project/apps/edicto/api.py
project/apps/edicto/constants.py
project/apps/edicto/serializer.py
project/settings/base.py
project/apps/edicto/api.py
View file @
c841101
from
rest_framework
import
viewsets
from
rest_framework
import
status
from
rest_framework
import
viewsets
,
mixins
,
status
from
rest_framework.response
import
Response
# from rest_framework.decorators import action
from
rest_framework.authentication
import
SessionAuthentication
,
BasicAuthentication
from
rest_framework.permissions
import
IsAuthenticated
from
rest_framework.decorators
import
action
from
datetime
import
datetime
from
.models
import
Edicto
from
.serializer
import
EdictoSerializer
from
.utils
import
contador
class
EdictoViewSet
(
viewsets
.
ModelViewSet
):
class
EdictoViewSet
(
mixins
.
CreateModelMixin
,
mixins
.
RetrieveModelMixin
,
mixins
.
UpdateModelMixin
,
mixins
.
DestroyModelMixin
,
mixins
.
ListModelMixin
,
viewsets
.
GenericViewSet
):
queryset
=
Edicto
.
objects
.
all
()
.
order_by
(
'id'
)
serializer_class
=
EdictoSerializer
authentication_classes
=
[
SessionAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAuthenticated
]
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
@action
(
detail
=
True
,
methods
=
[
'put'
,
'patch'
])
def
custom_update
(
self
,
request
):
edicto
=
request
.
data
.
get
(
'cuerpo_edicto'
)
cantidad_palabras
=
contador
(
edicto
)
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
instance
=
self
.
get_object
()
serializer
=
self
.
get_serializer
(
instance
,
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
serializer
.
save
(
cantidad_palabras
=
cantidad_palabras
)
serializer
.
save
(
cantidad_palabras
=
cantidad_palabras
,
fecha_actualizacion
=
datetime
.
now
())
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
)
def
perform_create
(
self
,
serializer
):
edicto
=
self
.
request
.
data
.
get
(
'cuerpo_edicto'
)
cantidad_palabras
=
contador
(
edicto
)
serializer
.
save
(
cantidad_palabras
=
cantidad_palabras
)
...
...
project/apps/edicto/constants.py
View file @
c841101
...
...
@@ -11,8 +11,9 @@ STATUS_CHOICE = [
(
INICIADO
,
_
(
'iniciado'
)),
(
PENDIENTE_DE_PAGO
,
_
(
'pendiente_de_pago'
)),
(
PUBLICADO
,
_
(
'publicado'
)),
(
APROBADO
,
_
(
'aprobado'
)),
(
APROBADO
,
_
(
'aprobado'
)),
(
RECHAZADO
,
_
(
'rechazado'
)),
]
EXTENSIONES_VALIDAS
=
[
".pdf"
,
".docx"
,
".jpg"
,
".jpeg"
,
".png"
]
EXTENSIONES_VALIDAS
=
[
"pdf"
,
"docx"
,
"jpg"
,
"jpeg"
,
"png"
]
...
...
project/apps/edicto/serializer.py
View file @
c841101
...
...
@@ -5,9 +5,6 @@ from .models import Edicto
class
EdictoSerializer
(
serializers
.
ModelSerializer
):
cantidad_palabras
=
serializers
.
IntegerField
(
read_only
=
True
)
fecha_creacion
=
serializers
.
DateTimeField
(
read_only
=
True
)
class
Meta
:
model
=
Edicto
fields
=
(
'usuario'
,
...
...
@@ -19,7 +16,9 @@ class EdictoSerializer(serializers.ModelSerializer):
'cantidad_copias'
,
'fecha_publicacion'
,
'archivo'
,
'fecha_creacion'
,)
'fecha_creacion'
,
)
read_only_fields
=
(
'cantidad_palabras'
,
'fecha_creacion'
)
@staticmethod
def
validate_archivo
(
value
):
...
...
project/settings/base.py
View file @
c841101
...
...
@@ -157,7 +157,7 @@ REST_FRAMEWORK = {
'rest_framework.authentication.BasicAuthentication'
,
'rest_framework.authentication.SessionAuthentication'
,
),
'DEFAULT_RENDERER_CLASSES'
:
(
'rest_framework_json_api.renderers.JSONRenderer'
,),
#
'DEFAULT_RENDERER_CLASSES': ('rest_framework_json_api.renderers.JSONRenderer',),
'DEFAULT_METADATA_CLASS'
:
'rest_framework_json_api.metadata.JSONAPIMetadata'
,
'NON_FIELD_ERRORS_KEY'
:
'error_messages'
}
...
...
Please
register
or
login
to post a comment