Enzo Yair

modificaciones_en_los_models,_serializer_y_parametros_en_el_llamado_a_la_funcion_contador_en_api.py

@@ -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)
  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 + ]
  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 + ]
@@ -5,7 +5,7 @@ from .utils import valid_extension @@ -5,7 +5,7 @@ from .utils import valid_extension
5 from .constants import STATUS_CHOICE 5 from .constants import STATUS_CHOICE
6 6
7 from usuario.models import Usuario 7 from usuario.models import Usuario
8 -from organismo.models import Organismo 8 +
9 9
10 # Create your models here. 10 # Create your models here.
11 11
@@ -27,15 +27,15 @@ class Precio (models.Model): @@ -27,15 +27,15 @@ class Precio (models.Model):
27 27
28 28
29 class Edicto(models.Model): 29 class Edicto(models.Model):
30 - usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE, verbose_name='Usuario') 30 + usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE, verbose_name='Usuario', null=True)
31 cuerpo_edicto = models.TextField(blank=False, null=False) 31 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]) 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) 33 + dias_publicar = models.PositiveIntegerField(blank=False, null=False)
  34 + cantidad_sellos = models.PositiveIntegerField(blank=False, null=False)
35 estado = models.CharField(max_length=150, choices=STATUS_CHOICE, default='inciado') 35 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() 36 + cantidad_palabras = models.IntegerField(blank=False, null=False)
  37 + cantidad_copias = models.PositiveIntegerField(blank=False, null=False)
  38 + fecha_publicacion = models.DateField(blank=False, null=False)
39 fecha_creacion = models.DateTimeField(auto_now_add=True) 39 fecha_creacion = models.DateTimeField(auto_now_add=True)
40 fecha_modificacion = models.DateTimeField(auto_now_add=True) 40 fecha_modificacion = models.DateTimeField(auto_now_add=True)
41 41
@@ -6,13 +6,15 @@ from .models import Edicto @@ -6,13 +6,15 @@ from .models import Edicto
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 = ('cuerpo_edicto',
  14 + 'cantidad_palabras',
14 'dias_publicar', 15 'dias_publicar',
15 'cantidad_sellos', 16 'cantidad_sellos',
16 - 'estado',  
17 'cantidad_copias', 17 'cantidad_copias',
18 - 'fecha_publicacion',) 18 + 'fecha_publicacion',
  19 + 'archivo',
  20 + 'fecha_creacion',)
@@ -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')
@@ -157,7 +157,7 @@ REST_FRAMEWORK = { @@ -157,7 +157,7 @@ REST_FRAMEWORK = {
157 'rest_framework.authentication.BasicAuthentication', 157 'rest_framework.authentication.BasicAuthentication',
158 'rest_framework.authentication.SessionAuthentication', 158 'rest_framework.authentication.SessionAuthentication',
159 ), 159 ),
160 - 'DEFAULT_RENDERER_CLASSES': ('rest_framework_json_api.renderers.JSONRenderer',), 160 + # 'DEFAULT_RENDERER_CLASSES': ('rest_framework_json_api.renderers.JSONRenderer',),
161 'DEFAULT_METADATA_CLASS': 'rest_framework_json_api.metadata.JSONAPIMetadata', 161 'DEFAULT_METADATA_CLASS': 'rest_framework_json_api.metadata.JSONAPIMetadata',
162 'NON_FIELD_ERRORS_KEY': 'error_messages' 162 'NON_FIELD_ERRORS_KEY': 'error_messages'
163 } 163 }