api.py
2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from django_filters.rest_framework import DjangoFilterBackend
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, ComprobanteFilter
from .models import Edicto, Precio, ComprobantePago
from .permissions import IsAdminOrAuthorized
from .serializers import EdictoSerializer, PrecioSerializer, ComprobanteSerializer
class EdictoViewSet(AuditoriaMixin, mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet):
serializer_class = EdictoSerializer
permission_classes = [IsAuthenticated, ]
filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
filterset_class = EdictoFilter
queryset = Edicto.objects.all()
ordering_fields = ('fecha_creacion', 'fecha_modificacion', 'id', 'estado', 'cantidad_palabras', 'creado_por')
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(mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet,
):
serializer_class = PrecioSerializer
permission_classes = [IsAuthenticated, IsAdminOrAuthorized]
filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
filterset_class = PrecioFilter
ordering_fields = ['vigencia_desde', ]
ordering = 'usuario'
queryset = Precio.objects.all()
class ComprobanteViewSet(mixins.UpdateModelMixin,
mixins.RetrieveModelMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet,
):
serializer_class = ComprobanteSerializer
permission_classes = [IsAuthenticated, ]
queryset = ComprobantePago.objects.all()
filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
filter_class = ComprobanteFilter
ordering_fields = ('id', 'monto_descuento', 'monto_total', 'fecha_pago')
ordering = 'id'