Enzo Yair

Merge branch 'feature/#21_agregar_actualizacion_de_formularios' into 'develop'

se agregan_el_metodo_actualizar



See merge request !17
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)
... ...
... ... @@ -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"]
... ...
... ... @@ -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):
... ...
... ... @@ -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'
}
... ...