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
Marta Miranda
2023-09-29 08:50:31 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
58780081554b6286ba3bebf3578c14fc4bbf60ec
58780081
1 parent
c07eb42d
Closed feature/67_agregar_auditorias
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
51 deletions
project/apps/core/api.py
project/apps/core/mixins.py
project/apps/edicto/api.py
project/apps/usuario/apps.py
project/apps/core/api.py
View file @
5878008
...
...
@@ -6,6 +6,7 @@ from django.conf import settings
import
datetime
from
actstream.models
import
actor_stream
from
actstream.models
import
Action
from
django.http
import
Http404
from
django_filters.rest_framework
import
DjangoFilterBackend
...
...
@@ -38,31 +39,31 @@ class AuditoriaViewSet(ReadOnlyModelViewSet):
serializer_class
=
ActionSerializer
filter_backends
=
(
DjangoFilterBackend
,
filters
.
OrderingFilter
)
ordering
=
'-timestamp'
#
# def get_queryset(self):
# queryset = super().get_queryset()
#
# if not self.action == 'list':
# return queryset
#
# # en el caso de que la accion sea listar, controlar que se filtre por fecha obligatoriamente
# usuario_id = self.request.GET.get('u_id', None)
# fecha_desde = self.request.GET.get('fecha_desde', None)
# fecha_hasta = self.request.GET.get('fecha_hasta', None)
#
# if not fecha_desde:
# return queryset.none()
#
# if not fecha_hasta or fecha_hasta < fecha_desde:
# fecha_hasta = datetime.datetime.now()
#
# if usuario_id:
# try:
# usuario = get_object_or_404(Usuario, id=usuario_id)
# queryset = usuario.actor_actions.public(timestamp__date__range=(fecha_desde, fecha_hasta))
# except Http404:
# return queryset.none()
# else:
# queryset = Action.objects.public(timestamp__date__range=(fecha_desde, fecha_hasta))
#
# return queryset
def
get_queryset
(
self
):
queryset
=
super
()
.
get_queryset
()
if
not
self
.
action
==
'list'
:
return
queryset
# en el caso de que la accion sea listar, controlar que se filtre por fecha obligatoriamente
usuario_id
=
self
.
request
.
GET
.
get
(
'usuario_id'
,
None
)
fecha_desde
=
self
.
request
.
GET
.
get
(
'fecha_desde'
,
None
)
fecha_hasta
=
self
.
request
.
GET
.
get
(
'fecha_hasta'
,
None
)
if
not
fecha_desde
:
return
queryset
.
none
()
if
not
fecha_hasta
or
fecha_hasta
<
fecha_desde
:
fecha_hasta
=
datetime
.
datetime
.
now
()
if
usuario_id
:
try
:
usuario
=
get_object_or_404
(
Usuario
,
id
=
usuario_id
)
queryset
=
usuario
.
actor_actions
.
public
(
timestamp__date__range
=
(
fecha_desde
,
fecha_hasta
))
except
Http404
:
return
queryset
.
none
()
else
:
queryset
=
Action
.
objects
.
public
(
timestamp__date__range
=
(
fecha_desde
,
fecha_hasta
))
return
queryset
...
...
project/apps/core/mixins.py
View file @
5878008
...
...
@@ -9,29 +9,29 @@ from core.constants import iniciado
from
core.serializers
import
ActionSerializer
# class FiltroObligatorioMixin(object):
# nombre_filtro_obligatorio: Optional[str] = None
#
# def get_queryset(self):
# queryset = super().get_queryset()
#
# if not self.action == 'list':
# return queryset
#
# # en el caso de que la accion sea listar, controlar que vengan los datos del filtro indicado
# filtro = self.request.GET.get(self.get_nombre_filtro_obligatorio(), None)
# if filtro:
# return queryset
#
# return queryset.none()
#
# def get_nombre_filtro_obligatorio(self):
# assert self.nombre_filtro_obligatorio is not None, (
# "Debe definir el atributo nombre_filtro_obligatorio a la clase '%s'"
# % self.__class__.__name__
# )
#
# return self.nombre_filtro_obligatorio
class
FiltroObligatorioMixin
(
object
):
nombre_filtro_obligatorio
:
Optional
[
str
]
=
None
def
get_queryset
(
self
):
queryset
=
super
()
.
get_queryset
()
if
not
self
.
action
==
'list'
:
return
queryset
# en el caso de que la accion sea listar, controlar que vengan los datos del filtro indicado
filtro
=
self
.
request
.
GET
.
get
(
self
.
get_nombre_filtro_obligatorio
(),
None
)
if
filtro
:
return
queryset
return
queryset
.
none
()
def
get_nombre_filtro_obligatorio
(
self
):
assert
self
.
nombre_filtro_obligatorio
is
not
None
,
(
"Debe definir el atributo nombre_filtro_obligatorio a la clase '
%
s'"
%
self
.
__class__
.
__name__
)
return
self
.
nombre_filtro_obligatorio
class
AuditoriaMixin
:
...
...
project/apps/edicto/api.py
View file @
5878008
...
...
@@ -3,6 +3,9 @@ from rest_framework import viewsets, filters, mixins
from
rest_framework.permissions
import
IsAuthenticated
from
core.mixins
import
AuditoriaMixin
from
rest_framework.decorators
import
action
from
core.serializers
import
ActionSerializer
from
rest_framework.response
import
Response
from
.filters
import
EdictoFilter
,
PrecioFilter
from
.models
import
Edicto
,
Precio
...
...
@@ -25,6 +28,21 @@ class EdictoViewSet(AuditoriaMixin, mixins.CreateModelMixin,
ordering
=
(
'fecha_publicacion'
,)
lookup_field
=
'uuid'
@action
(
methods
=
[
'GET'
],
detail
=
True
,
url_path
=
'obtener-historial'
,
serializer_class
=
ActionSerializer
)
def
obtener_historial
(
self
,
request
,
uuid
):
action_objects_id
=
list
(
Edicto
.
objects
.
filter
(
uuid
=
uuid
)
.
values_list
(
'id'
,
flat
=
True
))
serializer
=
self
.
obtener_historial_acciones
(
content_type
=
"edicto"
,
action_objects_id
=
action_objects_id
,
request
=
request
)
return
Response
(
serializer
.
data
)
class
PrecioViewSet
(
AuditoriaMixin
,
viewsets
.
ReadOnlyModelViewSet
):
serializer_class
=
PrecioSerializer
...
...
project/apps/usuario/apps.py
View file @
5878008
...
...
@@ -4,3 +4,10 @@ from django.apps import AppConfig
class
UsuarioConfig
(
AppConfig
):
default_auto_field
=
'django.db.models.BigAutoField'
name
=
'usuario'
def
ready
(
self
):
from
actstream
import
registry
registry
.
register
(
self
.
get_model
(
'Usuario'
))
default_app_config
=
'usuario.apps.UsuarioConfig'
...
...
Please
register
or
login
to post a comment