from rest_framework import viewsets
from .. import models, serializers
from django.http import HttpResponse
import logging

class PersonaViewSet(viewsets.ModelViewSet):
    queryset = models.Persona.objects.all()
    serializer_class = serializers.PersonaSerializer

    def destroy(self, request, pk=None):
        return HttpResponse('No permitido eliminar', status=405)
    
    def create(self, request):
        try:
            super().create(request)
        except Exception as e:
            # logging.warning(e.detail['rut'][0])
            if e.detail['rut']:
                return HttpResponse(e.detail['rut'][0], status=400)
            return HttpResponse(e, status=400)