Merge branch 'feature/#18_corregir_models_y_serializer' into 'develop'
Feature/#18 corregir models y serializer See merge request !15
Showing
13 changed files
with
216 additions
and
21 deletions
@@ -8,12 +8,12 @@ from .serializer import EdictoSerializer | @@ -8,12 +8,12 @@ from .serializer import EdictoSerializer | ||
8 | from .utils import contador | 8 | from .utils import contador |
9 | 9 | ||
10 | 10 | ||
11 | -class EdictoView(viewsets.ModelViewSet): | 11 | +class EdictoViewSet(viewsets.ModelViewSet): |
12 | queryset = Edicto.objects.all().order_by('id') | 12 | queryset = Edicto.objects.all().order_by('id') |
13 | serializer_class = EdictoSerializer | 13 | serializer_class = EdictoSerializer |
14 | 14 | ||
15 | def create(self, request, *args, **kwargs): | 15 | def create(self, request, *args, **kwargs): |
16 | - edicto = request.data.get('edicto') | 16 | + edicto = request.data.get('cuerpo_edicto') |
17 | cantidad_palabras = contador(edicto) | 17 | cantidad_palabras = contador(edicto) |
18 | 18 | ||
19 | serializer = self.get_serializer(data=request.data) | 19 | serializer = self.get_serializer(data=request.data) |
project/apps/edicto/migrations/0005_remove_edicto_dias_plubicar_edicto_dias_publicar_and_more.py
0 → 100644
1 | +# Generated by Django 4.1.9 on 2023-07-20 15:14 | ||
2 | + | ||
3 | +from django.db import migrations, models | ||
4 | + | ||
5 | + | ||
6 | +class Migration(migrations.Migration): | ||
7 | + | ||
8 | + dependencies = [ | ||
9 | + ('edicto', '0004_remove_edicto_organismo'), | ||
10 | + ] | ||
11 | + | ||
12 | + operations = [ | ||
13 | + migrations.RemoveField( | ||
14 | + model_name='edicto', | ||
15 | + name='dias_plubicar', | ||
16 | + ), | ||
17 | + migrations.AddField( | ||
18 | + model_name='edicto', | ||
19 | + name='dias_publicar', | ||
20 | + field=models.IntegerField(default=0), | ||
21 | + ), | ||
22 | + migrations.AlterField( | ||
23 | + model_name='edicto', | ||
24 | + name='cantidad_palabras', | ||
25 | + field=models.IntegerField(null=True), | ||
26 | + ), | ||
27 | + migrations.AlterField( | ||
28 | + model_name='edicto', | ||
29 | + name='cantidad_sellos', | ||
30 | + field=models.IntegerField(default=0), | ||
31 | + ), | ||
32 | + ] |
1 | +# Generated by Django 4.1.9 on 2023-07-22 16:07 | ||
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', '0005_remove_edicto_dias_plubicar_edicto_dias_publicar_and_more'), | ||
13 | + ] | ||
14 | + | ||
15 | + operations = [ | ||
16 | + migrations.AlterField( | ||
17 | + model_name='edicto', | ||
18 | + name='usuario', | ||
19 | + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Usuario'), | ||
20 | + ), | ||
21 | + ] |
project/apps/edicto/migrations/0007_alter_edicto_cantidad_palabras_alter_edicto_usuario.py
0 → 100644
1 | +# Generated by Django 4.1.9 on 2023-07-24 14:46 | ||
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', '0006_alter_edicto_usuario'), | ||
13 | + ] | ||
14 | + | ||
15 | + operations = [ | ||
16 | + migrations.AlterField( | ||
17 | + model_name='edicto', | ||
18 | + name='cantidad_palabras', | ||
19 | + field=models.IntegerField(default=0), | ||
20 | + ), | ||
21 | + migrations.AlterField( | ||
22 | + model_name='edicto', | ||
23 | + name='usuario', | ||
24 | + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Usuario'), | ||
25 | + ), | ||
26 | + ] |
1 | +# Generated by Django 4.1.9 on 2023-07-24 14:46 | ||
2 | + | ||
3 | +from django.db import migrations, models | ||
4 | + | ||
5 | + | ||
6 | +class Migration(migrations.Migration): | ||
7 | + | ||
8 | + dependencies = [ | ||
9 | + ('edicto', '0007_alter_edicto_cantidad_palabras_alter_edicto_usuario'), | ||
10 | + ] | ||
11 | + | ||
12 | + operations = [ | ||
13 | + migrations.AlterField( | ||
14 | + model_name='edicto', | ||
15 | + name='cantidad_palabras', | ||
16 | + field=models.IntegerField(), | ||
17 | + ), | ||
18 | + ] |
1 | +# Generated by Django 4.1.9 on 2023-07-25 13:01 | ||
2 | + | ||
3 | +from django.db import migrations, models | ||
4 | + | ||
5 | + | ||
6 | +class Migration(migrations.Migration): | ||
7 | + | ||
8 | + dependencies = [ | ||
9 | + ('edicto', '0008_alter_edicto_cantidad_palabras'), | ||
10 | + ] | ||
11 | + | ||
12 | + operations = [ | ||
13 | + migrations.AlterField( | ||
14 | + model_name='edicto', | ||
15 | + name='cantidad_sellos', | ||
16 | + field=models.IntegerField(), | ||
17 | + ), | ||
18 | + migrations.AlterField( | ||
19 | + model_name='edicto', | ||
20 | + name='dias_publicar', | ||
21 | + field=models.IntegerField(), | ||
22 | + ), | ||
23 | + migrations.AlterField( | ||
24 | + model_name='edicto', | ||
25 | + name='fecha_publicacion', | ||
26 | + field=models.DateField(), | ||
27 | + ), | ||
28 | + ] |
1 | +# Generated by Django 4.1.9 on 2023-07-25 13:32 | ||
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', '0009_alter_edicto_cantidad_sellos_and_more'), | ||
13 | + ] | ||
14 | + | ||
15 | + operations = [ | ||
16 | + migrations.AlterField( | ||
17 | + model_name='edicto', | ||
18 | + name='cantidad_copias', | ||
19 | + field=models.PositiveIntegerField(), | ||
20 | + ), | ||
21 | + migrations.AlterField( | ||
22 | + model_name='edicto', | ||
23 | + name='cantidad_palabras', | ||
24 | + field=models.PositiveIntegerField(), | ||
25 | + ), | ||
26 | + migrations.AlterField( | ||
27 | + model_name='edicto', | ||
28 | + name='cantidad_sellos', | ||
29 | + field=models.PositiveIntegerField(), | ||
30 | + ), | ||
31 | + migrations.AlterField( | ||
32 | + model_name='edicto', | ||
33 | + name='dias_publicar', | ||
34 | + field=models.PositiveIntegerField(), | ||
35 | + ), | ||
36 | + migrations.AlterField( | ||
37 | + model_name='edicto', | ||
38 | + name='usuario', | ||
39 | + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Usuario'), | ||
40 | + ), | ||
41 | + ] |
1 | +# Generated by Django 4.1.9 on 2023-07-25 13:43 | ||
2 | + | ||
3 | +from django.db import migrations, models | ||
4 | + | ||
5 | + | ||
6 | +class Migration(migrations.Migration): | ||
7 | + | ||
8 | + dependencies = [ | ||
9 | + ('edicto', '0010_alter_edicto_cantidad_copias_and_more'), | ||
10 | + ] | ||
11 | + | ||
12 | + operations = [ | ||
13 | + migrations.AlterField( | ||
14 | + model_name='edicto', | ||
15 | + name='cantidad_palabras', | ||
16 | + field=models.IntegerField(), | ||
17 | + ), | ||
18 | + ] |
1 | from django.db import models | 1 | from django.db import models |
2 | 2 | ||
3 | - | ||
4 | -from .utils import valid_extension | ||
5 | from .constants import STATUS_CHOICE | 3 | from .constants import STATUS_CHOICE |
6 | 4 | ||
7 | from usuario.models import Usuario | 5 | from usuario.models import Usuario |
8 | -from organismo.models import Organismo | ||
9 | 6 | ||
10 | # Create your models here. | 7 | # Create your models here. |
11 | 8 | ||
@@ -27,15 +24,15 @@ class Precio (models.Model): | @@ -27,15 +24,15 @@ class Precio (models.Model): | ||
27 | 24 | ||
28 | 25 | ||
29 | class Edicto(models.Model): | 26 | class Edicto(models.Model): |
30 | - usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE, verbose_name='Usuario') | 27 | + usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE, verbose_name='Usuario', null=True) |
31 | cuerpo_edicto = models.TextField(blank=False, null=False) | 28 | cuerpo_edicto = models.TextField(blank=False, null=False) |
32 | - archivo = models.FileField(upload_to="uploads/%Y/%m/%d/", null=False, blank=False, validators=[valid_extension]) | ||
33 | - dias_plubicar = models.FloatField(default=0.00, blank=False, null=False) | ||
34 | - cantidad_sellos = models.FloatField(default=0.00, blank=False, null=False) | 29 | + archivo = models.FileField(upload_to="uploads/%Y/%m/%d/", null=False, blank=False) |
30 | + dias_publicar = models.PositiveIntegerField(blank=False, null=False) | ||
31 | + cantidad_sellos = models.PositiveIntegerField(blank=False, null=False) | ||
35 | estado = models.CharField(max_length=150, choices=STATUS_CHOICE, default='inciado') | 32 | estado = models.CharField(max_length=150, choices=STATUS_CHOICE, default='inciado') |
36 | - cantidad_palabras = models.IntegerField() | ||
37 | - cantidad_copias = models.IntegerField() | ||
38 | - fecha_publicacion = models.DateTimeField() | 33 | + cantidad_palabras = models.IntegerField(blank=False, null=False) |
34 | + cantidad_copias = models.PositiveIntegerField(blank=False, null=False) | ||
35 | + fecha_publicacion = models.DateField(blank=False, null=False) | ||
39 | fecha_creacion = models.DateTimeField(auto_now_add=True) | 36 | fecha_creacion = models.DateTimeField(auto_now_add=True) |
40 | fecha_modificacion = models.DateTimeField(auto_now_add=True) | 37 | fecha_modificacion = models.DateTimeField(auto_now_add=True) |
41 | 38 |
1 | from rest_framework import serializers | 1 | from rest_framework import serializers |
2 | - | 2 | +from .constants import EXTENSIONES_VALIDAS |
3 | 3 | ||
4 | from .models import Edicto | 4 | from .models import Edicto |
5 | 5 | ||
6 | 6 | ||
7 | class EdictoSerializer(serializers.ModelSerializer): | 7 | class EdictoSerializer(serializers.ModelSerializer): |
8 | cantidad_palabras = serializers.IntegerField(read_only=True) | 8 | cantidad_palabras = serializers.IntegerField(read_only=True) |
9 | - created = serializers.DateTimeField(read_only=True) | 9 | + fecha_creacion = serializers.DateTimeField(read_only=True) |
10 | 10 | ||
11 | class Meta: | 11 | class Meta: |
12 | model = Edicto | 12 | model = Edicto |
13 | - fields = ('cuerpo_edicto', | 13 | + fields = ('usuario', |
14 | + 'cuerpo_edicto', | ||
15 | + 'estado', | ||
16 | + 'cantidad_palabras', | ||
14 | 'dias_publicar', | 17 | 'dias_publicar', |
15 | 'cantidad_sellos', | 18 | 'cantidad_sellos', |
16 | - 'estado', | ||
17 | 'cantidad_copias', | 19 | 'cantidad_copias', |
18 | - 'fecha_publicacion',) | 20 | + 'fecha_publicacion', |
21 | + 'archivo', | ||
22 | + 'fecha_creacion',) | ||
23 | + | ||
24 | + @staticmethod | ||
25 | + def validate_archivo(value): | ||
26 | + filename, extension = value.name.rsplit(".", 1) | ||
27 | + if extension.lower() not in EXTENSIONES_VALIDAS: | ||
28 | + raise serializers.ValidationError("Archivos permitidos: .pdf, .docx, .jpg, .jpeg, .png") | ||
29 | + return value |
@@ -4,10 +4,11 @@ import re | @@ -4,10 +4,11 @@ import re | ||
4 | 4 | ||
5 | def valid_extension(value): | 5 | def valid_extension(value): |
6 | if (not value.name.endswith('.pdf') and | 6 | if (not value.name.endswith('.pdf') and |
7 | + not value.name.endswith('.docx') and | ||
7 | not value.name.endswith('.jpeg') and | 8 | not value.name.endswith('.jpeg') and |
8 | not value.name.endswith('.png') and | 9 | not value.name.endswith('.png') and |
9 | not value.name.endswith('.jpg')): | 10 | not value.name.endswith('.jpg')): |
10 | - raise ValidationError("Archivos permitidos: .pdf .jpg, .jpeg, .png") | 11 | + raise ValidationError("Archivos permitidos: .pdf, .docx, .jpg, .jpeg, .png") |
11 | 12 | ||
12 | 13 | ||
13 | def contador(edicto): | 14 | def contador(edicto): |
@@ -17,5 +18,5 @@ def contador(edicto): | @@ -17,5 +18,5 @@ def contador(edicto): | ||
17 | cantidad_palabras = len(texto) | 18 | cantidad_palabras = len(texto) |
18 | cantidad_numeros = len(numeros) | 19 | cantidad_numeros = len(numeros) |
19 | cantidad_expresiones = len(expresiones) | 20 | cantidad_expresiones = len(expresiones) |
20 | - total_edicto = cantidad_palabras + cantidad_numeros + cantidad_expresiones - 1 | 21 | + total_edicto = cantidad_palabras + cantidad_numeros + cantidad_expresiones |
21 | return total_edicto | 22 | return total_edicto |
@@ -2,10 +2,10 @@ from rest_framework import routers | @@ -2,10 +2,10 @@ from rest_framework import routers | ||
2 | 2 | ||
3 | from organismo import api as organismo_api | 3 | from organismo import api as organismo_api |
4 | from usuario import api as usuario_api | 4 | from usuario import api as usuario_api |
5 | -from edicto.api import EdictoView | 5 | +from edicto.api import EdictoViewSet |
6 | # Define routes | 6 | # Define routes |
7 | router = routers.DefaultRouter() | 7 | router = routers.DefaultRouter() |
8 | 8 | ||
9 | router.register(prefix='usuario', viewset=usuario_api.UsuarioViewSet) | 9 | router.register(prefix='usuario', viewset=usuario_api.UsuarioViewSet) |
10 | router.register(prefix='organismo', viewset=organismo_api.OrganismoViewSet) | 10 | router.register(prefix='organismo', viewset=organismo_api.OrganismoViewSet) |
11 | -router.register(r'edicto', EdictoView, basename='edicto') | 11 | +router.register(r'edicto', EdictoViewSet, basename='edicto') |
-
Please register or login to post a comment