Martín Miranda

Merge branch 'feature/#18_corregir_models_y_serializer' into 'develop'

Feature/#18 corregir models y serializer



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