From 5c9ee803696e5fa54a62584e95d468244e7753e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rodrigues?= Date: Thu, 24 Oct 2019 13:02:41 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20#3022=20-=20Documento=20Acess=C3=B3rio=20?= =?UTF-8?q?(Mat=C3=A9ria=20Legislativa)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/forms.py | 21 ++++++++++++++---- .../migrations/0062_auto_20191024_1257.py | 22 +++++++++++++++++++ sapl/materia/models.py | 2 +- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 sapl/materia/migrations/0062_auto_20191024_1257.py diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 25302c845..57850135f 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -258,7 +258,7 @@ class MateriaLegislativaForm(FileFieldCheckMixin, ModelForm): if len(texto_original.name) > 200: raise ValidationError( "Certifique-se de que o nome do arquivo no campo 'Texto Original' tenha no " \ - "máximo 200 caracteres (ele possui {}).".format(len(texto_original.name)) + "máximo 200 caracteres (ele possui {})".format(len(texto_original.name)) ) if texto_original.size > MAX_DOC_UPLOAD_SIZE: raise ValidationError( @@ -367,9 +367,22 @@ class DocumentoAcessorioForm(FileFieldCheckMixin, ModelForm): arquivo = self.cleaned_data.get('arquivo', False) - if arquivo and arquivo.size > MAX_DOC_UPLOAD_SIZE: - raise ValidationError("O arquivo Texto Integral deve ser menor que {0:.1f} mb, o tamanho atual desse arquivo é {1:.1f} mb" - .format((MAX_DOC_UPLOAD_SIZE / 1024) / 1024, (arquivo.size / 1024) / 1024)) + if arquivo: + if len(arquivo.name) > 200: + raise ValidationError( + "Certifique-se de que o nome do arquivo no campo " \ + "'Texto Integral' tenha no máximo 200 caracteres " \ + "(ele possui {})".format(len(arquivo.name)) + ) + if arquivo.size > MAX_DOC_UPLOAD_SIZE: + raise ValidationError( + "O arquivo Texto Integral deve ser menor que " \ + "{0:.1f} mb, o tamanho atual desse arquivo é " \ + "{1:.1f} mb".format( + (MAX_DOC_UPLOAD_SIZE / 1024) / 1024, + (arquivo.size / 1024) / 1024 + ) + ) return self.cleaned_data diff --git a/sapl/materia/migrations/0062_auto_20191024_1257.py b/sapl/materia/migrations/0062_auto_20191024_1257.py new file mode 100644 index 000000000..5b8aa6375 --- /dev/null +++ b/sapl/materia/migrations/0062_auto_20191024_1257.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-10-24 15:57 +from __future__ import unicode_literals + +from django.db import migrations, models +import sapl.materia.models +import sapl.utils + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0061_auto_20191023_1404'), + ] + + operations = [ + migrations.AlterField( + model_name='documentoacessorio', + name='arquivo', + field=models.FileField(blank=True, max_length=300, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.materia.models.anexo_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Integral'), + ), + ] diff --git a/sapl/materia/models.py b/sapl/materia/models.py index 61b3cf7ef..afc841ca9 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -541,7 +541,7 @@ class DocumentoAcessorio(models.Model): arquivo = models.FileField( blank=True, null=True, - max_length=255, + max_length=300, upload_to=anexo_upload_path, verbose_name=_('Texto Integral'), storage=OverwriteStorage(),