Enzo Yair

Merge branch 'develop' of http://gitlab.catamarca.gob.ar/mvmiranda/boletin_api i…

…nto feature/#31_modificar_modelo_edicto
from django.contrib.auth.tokens import default_token_generator
from rest_framework import mixins, viewsets, status
from rest_framework.decorators import action
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import mixins, viewsets, status, filters
from rest_framework.exceptions import ValidationError
from rest_framework.parsers import JSONParser
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.response import Response
from core.permissions import CustomModelPermissions
from usuario.models import Usuario
from usuario.serializers import UsuarioSerializer, CambiarClaveSecretaSerializer
from usuario.serializers import UsuarioSerializer, CambiarClaveSecretaSerializer, UsuarioListaSerializer
from usuario.filters import UsuarioFilter
class UsuarioViewSet(mixins.RetrieveModelMixin, mixins.UpdateModelMixin, viewsets.GenericViewSet):
class UsuarioViewSet(mixins.RetrieveModelMixin, mixins.ListModelMixin, mixins.UpdateModelMixin,
viewsets.GenericViewSet):
queryset = Usuario.objects.all()
permission_classes = (IsAuthenticated,)
serializer_class = UsuarioSerializer
filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
filterset_class = UsuarioFilter
ordering_fields = ('last_name', 'first_name', 'cuil')
ordering = ('last_name',)
def get_object(self, base_method=False):
user = self.request.user
... ... @@ -22,6 +29,22 @@ class UsuarioViewSet(mixins.RetrieveModelMixin, mixins.UpdateModelMixin, viewset
return user
def get_serializer_class(self):
if self.action == 'list':
return UsuarioListaSerializer
return self.serializer_class
def get_permissions(self):
"""
Instantiates and returns the list of permissions that this view requires.
"""
permission_classes = self.permission_classes
if self.action == 'list':
permission_classes = [CustomModelPermissions]
return [permission() for permission in permission_classes]
@action(
methods=('patch',),
detail=False,
... ...
from django_filters import rest_framework as filters
from .models import Usuario
class UsuarioFilter(filters.FilterSet):
class Meta:
model = Usuario
fields = ('last_name',)
last_name = filters.CharFilter(field_name='last_name', lookup_expr='icontains')
... ...
... ... @@ -28,6 +28,17 @@ class UsuarioSerializer(serializers.ModelSerializer):
}
class UsuarioListaSerializer(serializers.ModelSerializer):
class Meta:
model = Usuario
fields = (
'username',
'first_name',
'last_name',
'cuil',
)
class CambiarClaveSecretaSerializer(DRFSerializer):
clave = serializers.CharField(max_length=128, write_only=True, required=True)
clave_nueva = serializers.CharField(max_length=128, write_only=True, required=True)
... ...