Merge branch 'Fix/fecha_modificacion' into 'develop'
Fix/fecha modificacion See merge request !51
Showing
8 changed files
with
163 additions
and
56 deletions
@@ -3,13 +3,11 @@ from django_filters.rest_framework import DjangoFilterBackend | @@ -3,13 +3,11 @@ from django_filters.rest_framework import DjangoFilterBackend | ||
3 | from rest_framework.response import Response | 3 | from rest_framework.response import Response |
4 | from rest_framework.permissions import IsAuthenticated | 4 | from rest_framework.permissions import IsAuthenticated |
5 | from rest_framework.decorators import action | 5 | from rest_framework.decorators import action |
6 | -from datetime import datetime | ||
7 | 6 | ||
8 | from .models import Edicto, Precio | 7 | from .models import Edicto, Precio |
9 | from .serializer import EdictoSerializer, PrecioSerializer | 8 | from .serializer import EdictoSerializer, PrecioSerializer |
10 | from .filters import EdictoFilter, PrecioFilter | 9 | from .filters import EdictoFilter, PrecioFilter |
11 | from .permissions import IsAdminOrAuthorized | 10 | from .permissions import IsAdminOrAuthorized |
12 | -from .utils import contador | ||
13 | 11 | ||
14 | 12 | ||
15 | class EdictoViewSet(mixins.CreateModelMixin, | 13 | class EdictoViewSet(mixins.CreateModelMixin, |
@@ -27,32 +25,6 @@ class EdictoViewSet(mixins.CreateModelMixin, | @@ -27,32 +25,6 @@ class EdictoViewSet(mixins.CreateModelMixin, | ||
27 | ordering = ('fecha_publicacion',) | 25 | ordering = ('fecha_publicacion',) |
28 | lookup_field = 'uuid' | 26 | lookup_field = 'uuid' |
29 | 27 | ||
30 | - def perform_create(self, serializer): | ||
31 | - edicto = self.request.data.get('cuerpo_edicto') | ||
32 | - cantidad_palabras = contador(edicto) | ||
33 | - usuario = self.request.user | ||
34 | - serializer.save(cantidad_palabras=cantidad_palabras, | ||
35 | - usuario=usuario, | ||
36 | - usuario_movimiento=usuario, | ||
37 | - ) | ||
38 | - | ||
39 | - @action(detail=True, methods=['put']) | ||
40 | - def custom_update(self, request): | ||
41 | - instance = self.get_object() | ||
42 | - serializer = self.get_serializer(instance, data=request.data) | ||
43 | - serializer.is_valid(raise_exception=True) | ||
44 | - | ||
45 | - edicto = request.data.get('cuerpo_edicto') | ||
46 | - cantidad_palabras = contador(edicto) | ||
47 | - usuario = self.request.user | ||
48 | - | ||
49 | - serializer.save(cantidad_palabras=cantidad_palabras, | ||
50 | - fecha_actualizacion=datetime.now(), | ||
51 | - usuario_movimiento=usuario, | ||
52 | - ) | ||
53 | - | ||
54 | - return Response(serializer.data, status=status.HTTP_200_OK) | ||
55 | - | ||
56 | 28 | ||
57 | class PrecioViewSet(viewsets.ReadOnlyModelViewSet): | 29 | class PrecioViewSet(viewsets.ReadOnlyModelViewSet): |
58 | serializer_class = PrecioSerializer | 30 | serializer_class = PrecioSerializer |
@@ -61,4 +33,4 @@ class PrecioViewSet(viewsets.ReadOnlyModelViewSet): | @@ -61,4 +33,4 @@ class PrecioViewSet(viewsets.ReadOnlyModelViewSet): | ||
61 | filterset_class = PrecioFilter | 33 | filterset_class = PrecioFilter |
62 | ordering_fields = ('usuario', ) | 34 | ordering_fields = ('usuario', ) |
63 | ordering = 'usuario' | 35 | ordering = 'usuario' |
64 | - queryset = Precio.objects.all() | 36 | + queryset = Precio.objects.all() |
@@ -7,7 +7,7 @@ from edicto.models import Edicto, Precio | @@ -7,7 +7,7 @@ from edicto.models import Edicto, Precio | ||
7 | class EdictoFilter(filters.FilterSet): | 7 | class EdictoFilter(filters.FilterSet): |
8 | class Meta: | 8 | class Meta: |
9 | model = Edicto | 9 | model = Edicto |
10 | - fields = {'usuario': ['exact'], | 10 | + fields = {'creado_por': ['exact'], |
11 | 'estado': ['exact'], | 11 | 'estado': ['exact'], |
12 | 'uuid': ['exact'], | 12 | 'uuid': ['exact'], |
13 | } | 13 | } |
1 | +# Generated by Django 4.1.9 on 2023-09-19 13:23 | ||
2 | + | ||
3 | +from django.conf import settings | ||
4 | +from django.db import migrations, models | ||
5 | +import django.db.models.deletion | ||
6 | + | ||
7 | + | ||
8 | +class Migration(migrations.Migration): | ||
9 | + | ||
10 | + dependencies = [ | ||
11 | + migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
12 | + ('edicto', '0015_edicto_usuario_movi'), | ||
13 | + ] | ||
14 | + | ||
15 | + operations = [ | ||
16 | + migrations.RemoveField( | ||
17 | + model_name='edicto', | ||
18 | + name='usuario', | ||
19 | + ), | ||
20 | + migrations.RemoveField( | ||
21 | + model_name='edicto', | ||
22 | + name='usuario_movimiento', | ||
23 | + ), | ||
24 | + migrations.AddField( | ||
25 | + model_name='edicto', | ||
26 | + name='creado_por', | ||
27 | + field=models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Usuario'), | ||
28 | + preserve_default=False, | ||
29 | + ), | ||
30 | + migrations.AddField( | ||
31 | + model_name='edicto', | ||
32 | + name='modificado_por', | ||
33 | + field=models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='udate_edicto', to=settings.AUTH_USER_MODEL), | ||
34 | + preserve_default=False, | ||
35 | + ), | ||
36 | + ] |
1 | +# Generated by Django 4.1.9 on 2023-09-19 13:29 | ||
2 | + | ||
3 | +from django.db import migrations, models | ||
4 | +import uuid | ||
5 | + | ||
6 | + | ||
7 | +class Migration(migrations.Migration): | ||
8 | + | ||
9 | + dependencies = [ | ||
10 | + ('edicto', '0016_remove_edicto_usuario_and_more'), | ||
11 | + ] | ||
12 | + | ||
13 | + operations = [ | ||
14 | + migrations.RemoveField( | ||
15 | + model_name='edicto', | ||
16 | + name='id', | ||
17 | + ), | ||
18 | + migrations.AlterField( | ||
19 | + model_name='edicto', | ||
20 | + name='uuid', | ||
21 | + field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True), | ||
22 | + ), | ||
23 | + ] |
1 | +# Generated by Django 4.1.9 on 2023-09-19 13:34 | ||
2 | + | ||
3 | +from django.db import migrations, models | ||
4 | + | ||
5 | + | ||
6 | +class Migration(migrations.Migration): | ||
7 | + | ||
8 | + dependencies = [ | ||
9 | + ('edicto', '0017_remove_edicto_id_alter_edicto_uuid'), | ||
10 | + ] | ||
11 | + | ||
12 | + operations = [ | ||
13 | + migrations.AlterField( | ||
14 | + model_name='edicto', | ||
15 | + name='fecha_modificacion', | ||
16 | + field=models.DateTimeField(auto_now=True), | ||
17 | + ), | ||
18 | + ] |
project/apps/edicto/migrations/0019_comprobantepago_archivo_alter_comprobantepago_edicto_and_more.py
0 → 100644
1 | +# Generated by Django 4.1.9 on 2023-09-20 13:27 | ||
2 | + | ||
3 | +from django.conf import settings | ||
4 | +from django.db import migrations, models | ||
5 | +import django.db.models.deletion | ||
6 | + | ||
7 | + | ||
8 | +class Migration(migrations.Migration): | ||
9 | + | ||
10 | + dependencies = [ | ||
11 | + migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
12 | + ('edicto', '0018_alter_edicto_fecha_modificacion'), | ||
13 | + ] | ||
14 | + | ||
15 | + operations = [ | ||
16 | + migrations.AddField( | ||
17 | + model_name='comprobantepago', | ||
18 | + name='archivo', | ||
19 | + field=models.FileField(blank=True, upload_to='uploads/%Y/%m/%d/'), | ||
20 | + ), | ||
21 | + migrations.AlterField( | ||
22 | + model_name='comprobantepago', | ||
23 | + name='edicto', | ||
24 | + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='edicto.edicto'), | ||
25 | + ), | ||
26 | + migrations.AlterField( | ||
27 | + model_name='comprobantepago', | ||
28 | + name='fecha_pago', | ||
29 | + field=models.DateTimeField(blank=True, null=True), | ||
30 | + ), | ||
31 | + migrations.AlterField( | ||
32 | + model_name='comprobantepago', | ||
33 | + name='monto', | ||
34 | + field=models.FloatField(editable=False), | ||
35 | + ), | ||
36 | + migrations.AlterField( | ||
37 | + model_name='comprobantepago', | ||
38 | + name='numero_comprobante', | ||
39 | + field=models.CharField(blank=True, max_length=300, null=True), | ||
40 | + ), | ||
41 | + migrations.AlterField( | ||
42 | + model_name='edicto', | ||
43 | + name='cantidad_palabras', | ||
44 | + field=models.IntegerField(editable=False), | ||
45 | + ), | ||
46 | + migrations.AlterField( | ||
47 | + model_name='edicto', | ||
48 | + name='modificado_por', | ||
49 | + field=models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='update_edicto', to=settings.AUTH_USER_MODEL), | ||
50 | + ), | ||
51 | + migrations.AlterField( | ||
52 | + model_name='precio', | ||
53 | + name='vigencia_hasta', | ||
54 | + field=models.DateField(blank=True, null=True), | ||
55 | + ), | ||
56 | + ] |
@@ -11,7 +11,7 @@ from usuario.models import Usuario | @@ -11,7 +11,7 @@ from usuario.models import Usuario | ||
11 | class Precio (models.Model): | 11 | class Precio (models.Model): |
12 | precio = models.FloatField(max_length=50, blank=False, null=False) | 12 | precio = models.FloatField(max_length=50, blank=False, null=False) |
13 | vigencia_desde = models.DateField() | 13 | vigencia_desde = models.DateField() |
14 | - vigencia_hasta = models.DateField() | 14 | + vigencia_hasta = models.DateField(blank=True, null=True) |
15 | usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE) | 15 | usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE) |
16 | moneda = models.CharField(max_length=50, blank=False, null=False, choices=MONEDA, default='peso_argentino') | 16 | moneda = models.CharField(max_length=50, blank=False, null=False, choices=MONEDA, default='peso_argentino') |
17 | precio_ejemplar = models.FloatField(max_length=50, blank=False, null=False) | 17 | precio_ejemplar = models.FloatField(max_length=50, blank=False, null=False) |
@@ -25,34 +25,35 @@ class Precio (models.Model): | @@ -25,34 +25,35 @@ class Precio (models.Model): | ||
25 | 25 | ||
26 | 26 | ||
27 | class Edicto(models.Model): | 27 | class Edicto(models.Model): |
28 | - uuid = models.UUIDField(unique=True, editable=False, default=uuid4) | ||
29 | - usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE, verbose_name='Usuario') | 28 | + uuid = models.UUIDField(unique=True, editable=False, default=uuid4, primary_key=True) |
29 | + creado_por = models.ForeignKey(Usuario, on_delete=models.CASCADE, verbose_name='Usuario', editable=False) | ||
30 | cuerpo_edicto = models.TextField(blank=False, null=False) | 30 | cuerpo_edicto = models.TextField(blank=False, null=False) |
31 | archivo = models.FileField(upload_to="uploads/%Y/%m/%d/", null=False, blank=False) | 31 | archivo = models.FileField(upload_to="uploads/%Y/%m/%d/", null=False, blank=False) |
32 | dias_publicar = models.PositiveIntegerField(blank=False, null=False) | 32 | dias_publicar = models.PositiveIntegerField(blank=False, null=False) |
33 | cantidad_sellos = models.PositiveIntegerField(blank=False, null=False) | 33 | cantidad_sellos = models.PositiveIntegerField(blank=False, null=False) |
34 | estado = models.CharField(max_length=150, choices=STATUS_CHOICE, default='inciado') | 34 | estado = models.CharField(max_length=150, choices=STATUS_CHOICE, default='inciado') |
35 | - cantidad_palabras = models.IntegerField(blank=False, null=False) | 35 | + cantidad_palabras = models.IntegerField(blank=False, null=False, editable=False) |
36 | cantidad_copias = models.PositiveIntegerField(blank=False, null=False) | 36 | cantidad_copias = models.PositiveIntegerField(blank=False, null=False) |
37 | fecha_publicacion = models.DateField(blank=True, null=True) | 37 | fecha_publicacion = models.DateField(blank=True, null=True) |
38 | observaciones = models.CharField(max_length=500, blank=True, null=True) | 38 | observaciones = models.CharField(max_length=500, blank=True, null=True) |
39 | - fecha_creacion = models.DateField(auto_now_add=True) | ||
40 | - fecha_modificacion = models.DateTimeField(auto_now_add=True) | ||
41 | - usuario_movimiento = models.ForeignKey(Usuario, on_delete=models.CASCADE, related_name='udate_edicto') | 39 | + fecha_creacion = models.DateField(auto_now_add=True, editable=False) |
40 | + fecha_modificacion = models.DateTimeField(auto_now=True, editable=False) | ||
41 | + modificado_por = models.ForeignKey(Usuario, on_delete=models.CASCADE, related_name='update_edicto', editable=False) | ||
42 | 42 | ||
43 | class Meta: | 43 | class Meta: |
44 | verbose_name = 'Edicto' | 44 | verbose_name = 'Edicto' |
45 | verbose_name_plural = 'Edictos' | 45 | verbose_name_plural = 'Edictos' |
46 | 46 | ||
47 | def __str__(self): | 47 | def __str__(self): |
48 | - return self.cuerpo_edicto | 48 | + return self.creado_por |
49 | 49 | ||
50 | 50 | ||
51 | class ComprobantePago(models.Model): | 51 | class ComprobantePago(models.Model): |
52 | - monto = models.FloatField(blank=False, null=False) | ||
53 | - numero_comprobante = models.CharField(max_length=300, blank=False, null=True) | ||
54 | - fecha_pago = models.DateTimeField(blank=False, null=True) | ||
55 | - edicto = models.ForeignKey(Edicto, on_delete=models.CASCADE) | 52 | + monto = models.FloatField(blank=False, null=False, editable=False) |
53 | + numero_comprobante = models.CharField(max_length=300, blank=True, null=True) | ||
54 | + fecha_pago = models.DateTimeField(blank=True, null=True) | ||
55 | + edicto = models.OneToOneField(Edicto, on_delete=models.CASCADE) | ||
56 | + archivo = models.FileField(upload_to="uploads/%Y/%m/%d/", blank=True, null=False) | ||
56 | 57 | ||
57 | class Meta: | 58 | class Meta: |
58 | verbose_name = 'ComprobantePago' | 59 | verbose_name = 'ComprobantePago' |
@@ -5,19 +5,19 @@ from .constants import EXTENSIONES_VALIDAS | @@ -5,19 +5,19 @@ from .constants import EXTENSIONES_VALIDAS | ||
5 | 5 | ||
6 | from .models import Edicto, Precio | 6 | from .models import Edicto, Precio |
7 | from usuario.serializers import UsuarioListaSerializer | 7 | from usuario.serializers import UsuarioListaSerializer |
8 | +from .utils import contador | ||
8 | 9 | ||
9 | 10 | ||
10 | class EdictoSerializer(serializers.ModelSerializer): | 11 | class EdictoSerializer(serializers.ModelSerializer): |
11 | included_serializers = { | 12 | included_serializers = { |
12 | - 'usuario': UsuarioListaSerializer, | ||
13 | - 'usuario_movimiento': UsuarioListaSerializer, | 13 | + 'creado_por': UsuarioListaSerializer, |
14 | + 'modificado_por': UsuarioListaSerializer, | ||
14 | } | 15 | } |
15 | 16 | ||
16 | class Meta: | 17 | class Meta: |
17 | model = Edicto | 18 | model = Edicto |
18 | - fields = ('uuid', | ||
19 | - 'usuario', | ||
20 | - 'usuario_movimiento', | 19 | + fields = ('creado_por', |
20 | + 'modificado_por', | ||
21 | 'estado', | 21 | 'estado', |
22 | 'cuerpo_edicto', | 22 | 'cuerpo_edicto', |
23 | 'cantidad_palabras', | 23 | 'cantidad_palabras', |
@@ -28,19 +28,20 @@ class EdictoSerializer(serializers.ModelSerializer): | @@ -28,19 +28,20 @@ class EdictoSerializer(serializers.ModelSerializer): | ||
28 | 'fecha_creacion', | 28 | 'fecha_creacion', |
29 | 'observaciones', | 29 | 'observaciones', |
30 | 'fecha_publicacion', | 30 | 'fecha_publicacion', |
31 | + 'fecha_modificacion' | ||
31 | 32 | ||
32 | ) | 33 | ) |
33 | 34 | ||
34 | - read_only_fields = ('usuario', 'usuario_movimiento', | ||
35 | - 'fecha_publicacion', 'cantidad_palabras', | ||
36 | - 'fecha_creacion', | 35 | + read_only_fields = ('fecha_publicacion', |
37 | ) | 36 | ) |
38 | 37 | ||
39 | - def to_representation(self, instance): | ||
40 | - data = super().to_representation(instance) | ||
41 | - user = self.context['request'].user | ||
42 | - if not user.is_staff: | ||
43 | - data['fecha_publicacion'] = instance.fecha_publicacion | 38 | + def validate(self, data): |
39 | + edicto = data.get('cuerpo_edicto', '') | ||
40 | + data['cantidad_palabras'] = contador(edicto) | ||
41 | + request = self.context['request'] | ||
42 | + if request.method == 'POST': | ||
43 | + data['creado_por'] = request.user | ||
44 | + data['modificado_por'] = request.user | ||
44 | return data | 45 | return data |
45 | 46 | ||
46 | @staticmethod | 47 | @staticmethod |
@@ -65,4 +66,4 @@ class PrecioSerializer(serializers.ModelSerializer): | @@ -65,4 +66,4 @@ class PrecioSerializer(serializers.ModelSerializer): | ||
65 | 66 | ||
66 | included_serializers = { | 67 | included_serializers = { |
67 | 'usuario': UsuarioListaSerializer | 68 | 'usuario': UsuarioListaSerializer |
68 | - } | ||
69 | + } |
-
Please register or login to post a comment