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-24 13:34:52 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
73115c90cb32774cc1d40d87ba07c1ba77655bb0
73115c90
1 parent
1c0aeb82
se agrego include
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
24 deletions
project/apps/edicto/api.py
project/apps/edicto/filters.py
project/apps/edicto/serializer.py
project/apps/edicto/utils.py
project/router.py
project/apps/edicto/api.py
View file @
73115c9
...
...
@@ -17,19 +17,41 @@ class EdictoViewSet(mixins.CreateModelMixin,
mixins
.
ListModelMixin
,
viewsets
.
GenericViewSet
):
queryset
=
Edicto
.
objects
.
all
()
.
order_by
(
'id'
)
serializer_class
=
EdictoSerializer
permission_classes
=
[
IsAuthenticated
,
]
def
get_queryset
(
self
):
return
Edicto
.
objects
.
all
()
.
order_by
(
'usuario_id'
)
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
fields_to_select
=
[
'id'
,
'estado'
,
'cuerpo_edicto'
,
'cantidad_palabras'
,
'dias_publicar'
,
'cantidad_sellos'
,
'cantidad_copias'
,
'archivo'
,
'fecha_creacion'
,
'observaciones'
,
'fecha_publicacion'
,
]
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
()
.
values
(
*
fields_to_select
))
user_id
=
request
.
user
.
id
response_data
=
{
'user_id'
:
user_id
,
'edictos'
:
queryset
,
}
return
Response
(
response_data
)
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'
])
@action
(
detail
=
True
,
methods
=
[
'patch'
])
def
custom_update
(
self
,
request
):
edicto
=
request
.
data
.
get
(
'cuerpo_edicto'
)
cantidad_palabras
=
contador
(
edicto
)
...
...
@@ -39,11 +61,7 @@ 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
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
class
PrecioViewSet
(
mixins
.
CreateModelMixin
,
...
...
project/apps/edicto/filters.py
0 → 100644
View file @
73115c9
from
django_filters
import
rest_framework
as
filters
from
edicto.models
import
Edicto
class
EdictoFilters
(
filters
.
FilterSet
):
models
=
Edicto
fields
=
(
'estado'
,
'fecha_publicacion'
,)
...
...
project/apps/edicto/serializer.py
View file @
73115c9
...
...
@@ -7,15 +7,13 @@ from usuario.serializers import UsuarioSerializer
class
EdictoSerializer
(
serializers
.
ModelSerializer
):
edicto_id
=
serializers
.
ReadOnlyField
(
source
=
'id'
)
class
Meta
:
model
=
Edicto
fields
=
(
'edicto_id'
,
'fecha_publicacion'
,
'cuerpo_edicto'
,
'estado'
,
'cuerpo_edicto'
,
'cantidad_palabras'
,
'dias_publicar'
,
'cantidad_sellos'
,
...
...
@@ -24,18 +22,18 @@ class EdictoSerializer(serializers.ModelSerializer):
'fecha_creacion'
,
'observaciones'
,
)
read_only_fields
=
(
'cantidad_palabras'
,
'fecha_creacion'
)
included_serializers
=
{
'usuario'
:
'usuario.serializers.UsuarioSerializer'
,
}
read_only_fields
=
(
'fecha_publicacion'
,
'cantidad_palabras'
,
'fecha_creacion'
)
def
to_representation
(
self
,
instance
):
data
=
super
()
.
to_representation
(
instance
)
user
=
self
.
context
[
'request'
]
.
user
if
self
.
context
[
'view'
]
.
include_fecha_publicacion
():
if
not
user
.
is_staff
:
data
[
'fecha_publicacion'
]
=
instance
.
fecha_publicacion
if
user
.
is_staff
:
data
[
'user_id'
]
=
user
.
id
return
data
@staticmethod
...
...
@@ -46,6 +44,7 @@ class EdictoSerializer(serializers.ModelSerializer):
return
value
class
PrecioSerializer
(
serializers
.
ModelSerializer
):
usuario
=
UsuarioSerializer
()
...
...
project/apps/edicto/utils.py
View file @
73115c9
...
...
@@ -2,11 +2,9 @@ import re
def
contador
(
edicto
):
numeros
=
re
.
findall
(
r'
\
b
\
d+(?:
\
.
\
d+)?
\
b'
,
edicto
)
expresiones
=
re
.
findall
(
r'
\
(
\
.
\
.
\
.'
,
edicto
)
texto
=
edicto
.
split
()
cantidad_palabras
=
len
(
texto
)
cantidad_numeros
=
len
(
numeros
)
-
1
cantidad_expresiones
=
len
(
expresiones
)
total_edicto
=
cantidad_palabras
+
cantidad_
numeros
+
cantidad_
expresiones
total_edicto
=
cantidad_palabras
+
cantidad_expresiones
return
total_edicto
...
...
project/router.py
View file @
73115c9
...
...
@@ -2,12 +2,14 @@ from rest_framework import routers
from
organismo
import
api
as
organismo_api
from
usuario
import
api
as
usuario_api
from
edicto.api
import
EdictoViewSet
from
edicto
import
api
as
edicto_api
# Define routes
router
=
routers
.
DefaultRouter
()
router
.
register
(
prefix
=
'usuario'
,
viewset
=
usuario_api
.
UsuarioViewSet
)
router
.
register
(
prefix
=
'organismo'
,
viewset
=
organismo_api
.
OrganismoViewSet
)
router
.
register
(
prefix
=
'edicto'
,
viewset
=
edicto_api
.
EdictoViewSet
)
router
.
register
(
r'edicto'
,
EdictoViewSet
,
basename
=
'edicto'
)
router
.
register
(
prefix
=
'precio'
,
viewset
=
edicto_api
.
PrecioViewSet
)
...
...
Please
register
or
login
to post a comment