diff --git a/sapl/norma/forms.py b/sapl/norma/forms.py index b3846b033..333da3d1e 100644 --- a/sapl/norma/forms.py +++ b/sapl/norma/forms.py @@ -278,7 +278,10 @@ class AnexoNormaJuridicaForm(FileFieldCheckMixin, ModelForm): logger = logging.getLogger(__name__) - anexo_arquivo = forms.FileField(required=True) + anexo_arquivo = forms.FileField( + required=True, + label="Arquivo Anexo" + ) class Meta: model = AnexoNormaJuridica @@ -295,9 +298,24 @@ class AnexoNormaJuridicaForm(FileFieldCheckMixin, ModelForm): anexo_arquivo = self.cleaned_data.get('anexo_arquivo', False) - if anexo_arquivo and anexo_arquivo.size > MAX_DOC_UPLOAD_SIZE: - raise ValidationError("O Arquivo Anexo deve ser menor que {0:.1f} mb, o tamanho atual desse arquivo é {1:.1f} mb" \ - .format((MAX_DOC_UPLOAD_SIZE/1024)/1024, (anexo_arquivo.size/1024)/1024)) + if anexo_arquivo: + if len(anexo_arquivo.name) > 200: + raise ValidationError( + "Certifique-se de que o nome do arquivo no " \ + "campo 'Arquivo Anexo' tenha no máximo 200 " \ + "caracteres (ele possui {})".format( + len(anexo_arquivo.name) + ) + ) + if anexo_arquivo.size > MAX_DOC_UPLOAD_SIZE: + raise ValidationError( + "O Arquivo Anexo deve ser menor que " \ + "{0:.1f} mb, o tamanho atual desse arquivo é " \ + "{1:.1f} mb".format( + (MAX_DOC_UPLOAD_SIZE/1024)/1024, + (anexo_arquivo.size/1024)/1024 + ) + ) return cleaned_data diff --git a/sapl/norma/migrations/0029_auto_20191024_1344.py b/sapl/norma/migrations/0029_auto_20191024_1344.py new file mode 100644 index 000000000..2768e606e --- /dev/null +++ b/sapl/norma/migrations/0029_auto_20191024_1344.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-10-24 16:44 +from __future__ import unicode_literals + +from django.db import migrations, models +import sapl.norma.models +import sapl.utils + + +class Migration(migrations.Migration): + + dependencies = [ + ('norma', '0028_auto_20191024_1330'), + ] + + operations = [ + migrations.AlterField( + model_name='anexonormajuridica', + name='anexo_arquivo', + field=models.FileField(blank=True, max_length=300, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.norma.models.norma_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Arquivo Anexo'), + ), + ] diff --git a/sapl/norma/models.py b/sapl/norma/models.py index 68ccc8482..bc93c7439 100644 --- a/sapl/norma/models.py +++ b/sapl/norma/models.py @@ -357,7 +357,7 @@ class AnexoNormaJuridica(models.Model): max_length=250 ) anexo_arquivo = models.FileField( - max_length=200, + max_length=300, blank=True, null=True, upload_to=norma_upload_path,