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
Enzo Yair
2023-09-19 09:41:02 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
aab07bc06201d26a1e0786e391da17ce818175a0
aab07bc0
1 parent
38f0f2e5
se cambio los nombres de usuarios y usuario movimiento
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
44 deletions
project/apps/edicto/api.py
project/apps/edicto/filters.py
project/apps/edicto/migrations/0016_rename_usuario_edicto_creado_por_and_more.py
project/apps/edicto/models.py
project/apps/edicto/serializer.py
project/apps/edicto/api.py
View file @
aab07bc
...
...
@@ -3,13 +3,11 @@ from django_filters.rest_framework import DjangoFilterBackend
from
rest_framework.response
import
Response
from
rest_framework.permissions
import
IsAuthenticated
from
rest_framework.decorators
import
action
from
datetime
import
datetime
from
.models
import
Edicto
,
Precio
from
.serializer
import
EdictoSerializer
,
PrecioSerializer
from
.filters
import
EdictoFilter
,
PrecioFilter
from
.permissions
import
IsAdminOrAuthorized
from
.utils
import
contador
class
EdictoViewSet
(
mixins
.
CreateModelMixin
,
...
...
@@ -27,32 +25,6 @@ class EdictoViewSet(mixins.CreateModelMixin,
ordering
=
(
'fecha_publicacion'
,)
lookup_field
=
'uuid'
def
perform_create
(
self
,
serializer
):
edicto
=
self
.
request
.
data
.
get
(
'cuerpo_edicto'
)
cantidad_palabras
=
contador
(
edicto
)
usuario
=
self
.
request
.
user
serializer
.
save
(
cantidad_palabras
=
cantidad_palabras
,
usuario
=
usuario
,
usuario_movimiento
=
usuario
,
)
@action
(
detail
=
True
,
methods
=
[
'put'
])
def
custom_update
(
self
,
request
):
instance
=
self
.
get_object
()
serializer
=
self
.
get_serializer
(
instance
,
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
edicto
=
request
.
data
.
get
(
'cuerpo_edicto'
)
cantidad_palabras
=
contador
(
edicto
)
usuario
=
self
.
request
.
user
serializer
.
save
(
cantidad_palabras
=
cantidad_palabras
,
fecha_actualizacion
=
datetime
.
now
(),
usuario_movimiento
=
usuario
,
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
class
PrecioViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
serializer_class
=
PrecioSerializer
...
...
@@ -61,4 +33,4 @@ class PrecioViewSet(viewsets.ReadOnlyModelViewSet):
filterset_class
=
PrecioFilter
ordering_fields
=
(
'usuario'
,
)
ordering
=
'usuario'
queryset
=
Precio
.
objects
.
all
()
queryset
=
Precio
.
objects
.
all
()
\ No newline at end of file
...
...
project/apps/edicto/filters.py
View file @
aab07bc
...
...
@@ -7,7 +7,7 @@ from edicto.models import Edicto, Precio
class
EdictoFilter
(
filters
.
FilterSet
):
class
Meta
:
model
=
Edicto
fields
=
{
'
usuario
'
:
[
'exact'
],
fields
=
{
'
creado_por
'
:
[
'exact'
],
'estado'
:
[
'exact'
],
'uuid'
:
[
'exact'
],
}
...
...
project/apps/edicto/migrations/0016_rename_usuario_edicto_creado_por_and_more.py
0 → 100644
View file @
aab07bc
# Generated by Django 4.1.9 on 2023-09-19 12:40
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'edicto'
,
'0015_edicto_usuario_movi'
),
]
operations
=
[
migrations
.
RenameField
(
model_name
=
'edicto'
,
old_name
=
'usuario'
,
new_name
=
'creado_por'
,
),
migrations
.
RenameField
(
model_name
=
'edicto'
,
old_name
=
'usuario_movimiento'
,
new_name
=
'modificado_por'
,
),
]
...
...
project/apps/edicto/models.py
View file @
aab07bc
...
...
@@ -26,7 +26,7 @@ class Precio (models.Model):
class
Edicto
(
models
.
Model
):
uuid
=
models
.
UUIDField
(
unique
=
True
,
editable
=
False
,
default
=
uuid4
)
usuario
=
models
.
ForeignKey
(
Usuario
,
on_delete
=
models
.
CASCADE
,
verbose_name
=
'Usuario'
)
creado_por
=
models
.
ForeignKey
(
Usuario
,
on_delete
=
models
.
CASCADE
,
verbose_name
=
'Usuario'
)
cuerpo_edicto
=
models
.
TextField
(
blank
=
False
,
null
=
False
)
archivo
=
models
.
FileField
(
upload_to
=
"uploads/
%
Y/
%
m/
%
d/"
,
null
=
False
,
blank
=
False
)
dias_publicar
=
models
.
PositiveIntegerField
(
blank
=
False
,
null
=
False
)
...
...
@@ -38,7 +38,7 @@ class Edicto(models.Model):
observaciones
=
models
.
CharField
(
max_length
=
500
,
blank
=
True
,
null
=
True
)
fecha_creacion
=
models
.
DateField
(
auto_now_add
=
True
)
fecha_modificacion
=
models
.
DateTimeField
(
auto_now_add
=
True
)
usuario_movimiento
=
models
.
ForeignKey
(
Usuario
,
on_delete
=
models
.
CASCADE
,
related_name
=
'udate_edicto'
)
modificado_por
=
models
.
ForeignKey
(
Usuario
,
on_delete
=
models
.
CASCADE
,
related_name
=
'udate_edicto'
)
class
Meta
:
verbose_name
=
'Edicto'
...
...
project/apps/edicto/serializer.py
View file @
aab07bc
...
...
@@ -5,19 +5,19 @@ from .constants import EXTENSIONES_VALIDAS
from
.models
import
Edicto
,
Precio
from
usuario.serializers
import
UsuarioListaSerializer
from
.utils
import
contador
class
EdictoSerializer
(
serializers
.
ModelSerializer
):
included_serializers
=
{
'usuario'
:
UsuarioListaSerializer
,
'usuario_movimiento'
:
UsuarioListaSerializer
,
'creado_por'
:
UsuarioListaSerializer
,
'modificado_por'
:
UsuarioListaSerializer
,
}
class
Meta
:
model
=
Edicto
fields
=
(
'uuid'
,
'usuario'
,
'usuario_movimiento'
,
fields
=
(
'creado_por'
,
'modificado_por'
,
'estado'
,
'cuerpo_edicto'
,
'cantidad_palabras'
,
...
...
@@ -28,19 +28,24 @@ class EdictoSerializer(serializers.ModelSerializer):
'fecha_creacion'
,
'observaciones'
,
'fecha_publicacion'
,
'fecha_modificacion'
)
read_only_fields
=
(
'
usuario'
,
'usuario_movimiento
'
,
read_only_fields
=
(
'
creado_por'
,
'modificado_por
'
,
'fecha_publicacion'
,
'cantidad_palabras'
,
'fecha_creacion'
,
'fecha_modificacion'
,
)
def
to_representation
(
self
,
instance
):
data
=
super
()
.
to_representation
(
instance
)
user
=
self
.
context
[
'request'
]
.
user
if
not
user
.
is_staff
:
data
[
'fecha_publicacion'
]
=
instance
.
fecha_publicacion
def
validate
(
self
,
data
):
edicto
=
data
.
get
(
'cuerpo_edicto'
,
''
)
cantidad_palabras
=
contador
(
edicto
)
data
[
'cantidad_palabras'
]
=
cantidad_palabras
request
=
self
.
context
[
'request'
]
if
request
.
method
==
'POST'
:
data
[
'creado_por'
]
=
request
.
user
data
[
'modificado_por'
]
=
request
.
user
return
data
@staticmethod
...
...
@@ -65,4 +70,4 @@ class PrecioSerializer(serializers.ModelSerializer):
included_serializers
=
{
'usuario'
:
UsuarioListaSerializer
}
\ No newline at end of file
}
...
...
Please
register
or
login
to post a comment