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
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)
... ...
# 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(),
),
]
... ...
... ... @@ -5,7 +5,7 @@ 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 +27,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)
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)
... ...
... ... @@ -6,13 +6,15 @@ 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',
'cantidad_palabras',
'dias_publicar',
'cantidad_sellos',
'estado',
'cantidad_copias',
'fecha_publicacion',)
'fecha_publicacion',
'archivo',
'fecha_creacion',)
... ...
... ... @@ -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')
... ...
... ... @@ -157,7 +157,7 @@ REST_FRAMEWORK = {
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_RENDERER_CLASSES': ('rest_framework_json_api.renderers.JSONRenderer',),
# 'DEFAULT_RENDERER_CLASSES': ('rest_framework_json_api.renderers.JSONRenderer',),
'DEFAULT_METADATA_CLASS': 'rest_framework_json_api.metadata.JSONAPIMetadata',
'NON_FIELD_ERRORS_KEY': 'error_messages'
}
... ...