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-08-23 13:18:56 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1c0aeb82c02283f853686d74b7929d51860d6d23
1c0aeb82
1 parent
a50385a6
feature/#31_modificar_modelo_edicto
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
35 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 @
1c0aeb8
...
...
@@ -21,6 +21,14 @@ class EdictoViewSet(mixins.CreateModelMixin,
serializer_class
=
EdictoSerializer
permission_classes
=
[
IsAuthenticated
,
]
def
perform_create
(
self
,
serializer
):
edicto
=
self
.
request
.
data
.
get
(
'cuerpo_edicto'
)
cantidad_palabras
=
contador
(
edicto
)
serializer
.
save
(
cantidad_palabras
=
cantidad_palabras
,
usuario
=
self
.
request
.
user
)
def
custom_get_method
(
self
,
request
):
instance
=
self
.
get_object
()
@action
(
detail
=
True
,
methods
=
[
'put'
,
'patch'
])
def
custom_update
(
self
,
request
):
edicto
=
request
.
data
.
get
(
'cuerpo_edicto'
)
...
...
@@ -31,35 +39,11 @@ class EdictoViewSet(mixins.CreateModelMixin,
serializer
.
is_valid
(
raise_exception
=
True
)
serializer
.
save
(
cantidad_palabras
=
cantidad_palabras
,
fecha_actualizacion
=
datetime
.
now
())
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
def
perform_create
(
self
,
serializer
):
edicto
=
self
.
request
.
data
.
get
(
'cuerpo_edicto'
)
cantidad_palabras
=
contador
(
edicto
)
serializer
.
save
(
cantidad_palabras
=
cantidad_palabras
)
def
include_fecha_publicacion
(
self
):
return
self
.
request
.
user
.
is_staff
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
for
data
in
serializer
.
data
:
if
self
.
include_fecha_publicacion
():
edicto
=
queryset
.
get
(
id
=
data
[
'edicto_id'
])
data
[
'fecha_publicacion'
]
=
edicto
.
fecha_publicacion
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
serializer
=
self
.
get_serializer
(
instance
)
if
self
.
include_fecha_publicacion
():
serializer
.
data
[
'fecha_publicacion'
]
=
instance
.
fecha_publicacion
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
class
PrecioViewSet
(
mixins
.
CreateModelMixin
,
...
...
project/apps/edicto/constants.py
View file @
1c0aeb8
...
...
@@ -16,7 +16,7 @@ STATUS_CHOICE = [
]
EXTENSIONES_VALIDAS
=
[
"pdf"
,
"docx"
,]
EXTENSIONES_VALIDAS
=
"pdf"
,
PESOS
=
'peso_argentino'
...
...
project/apps/edicto/serializer.py
View file @
1c0aeb8
...
...
@@ -12,8 +12,8 @@ class EdictoSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
Edicto
fields
=
(
'usuario'
,
'edicto_id'
,
fields
=
(
'edicto_id'
,
'fecha_publicacion'
,
'cuerpo_edicto'
,
'estado'
,
'cantidad_palabras'
,
...
...
@@ -25,24 +25,24 @@ class EdictoSerializer(serializers.ModelSerializer):
'observaciones'
,
)
read_only_fields
=
(
'cantidad_palabras'
,
'fecha_creacion'
)
included_serializers
=
{
'usuario'
:
'usuario.serializers.UsuarioSerializer'
,
}
def
to_representation
(
self
,
instance
):
data
=
super
()
.
to_representation
(
instance
)
user
=
self
.
context
[
'request'
]
.
user
if
user
.
is_staff
:
if
self
.
context
[
'view'
]
.
include_fecha_publicacion
()
:
data
[
'fecha_publicacion'
]
=
instance
.
fecha_publicacion
if
user
.
is_staff
:
data
[
'user_id'
]
=
user
.
id
return
data
@staticmethod
def
validate_archivo
(
value
):
filename
,
extension
=
value
.
name
.
rsplit
(
"."
,
1
)
if
extension
.
lower
()
not
in
EXTENSIONES_VALIDAS
:
raise
serializers
.
ValidationError
(
"Archivos permitidos: .pdf
, .docx, .jpg, .png
"
)
raise
serializers
.
ValidationError
(
"Archivos permitidos: .pdf"
)
return
value
...
...
@@ -64,7 +64,7 @@ class PrecioSerializer(serializers.ModelSerializer):
user
=
request
.
user
if
request
else
None
if
not
user
or
user
.
is_anonymous
:
raise
serializers
.
ValidationError
(
"El usuario debe estar autenticado."
)
if
not
user
.
e
s_staff
:
if
not
user
.
i
s_staff
:
raise
serializers
.
ValidationError
(
"El usuario no es parte del personal designado."
)
return
data
...
...
project/settings/base.py
View file @
1c0aeb8
...
...
@@ -162,7 +162,7 @@ REST_FRAMEWORK = {
'NON_FIELD_ERRORS_KEY'
:
'error_messages'
}
ACTIVAR_HERRAMIENTAS_DEBUGGING
=
env
.
bool
(
'ACTIVAR_HERRAMIENTAS_DEBUGGING'
,
default
=
Fals
e
)
ACTIVAR_HERRAMIENTAS_DEBUGGING
=
env
.
bool
(
'ACTIVAR_HERRAMIENTAS_DEBUGGING'
,
default
=
Tru
e
)
if
ACTIVAR_HERRAMIENTAS_DEBUGGING
:
INTERNAL_IPS
=
[
'127.0.0.1'
]
INSTALLED_APPS
+=
(
'debug_toolbar'
,
'django_extensions'
)
...
...
Please
register
or
login
to post a comment