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-08-28 09:25:15 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2f3d1728678df197cc372f3b5fc81c25d9356ffe
2f3d1728
1 parent
a50385a6
Closed feature/#33_serializar_usuarios
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
4 deletions
project/apps/usuario/api.py
project/apps/usuario/filters.py
project/apps/usuario/serializers.py
project/apps/usuario/api.py
View file @
2f3d172
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
,
...
...
project/apps/usuario/filters.py
0 → 100644
View file @
2f3d172
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'
)
...
...
project/apps/usuario/serializers.py
View file @
2f3d172
...
...
@@ -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
)
...
...
Please
register
or
login
to post a comment