From 6e3be4ab2e9e8aaa36585811a3c3ba9d481df6a6 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 13 Apr 2016 10:17:40 -0300 Subject: [PATCH] =?UTF-8?q?Adiciona=20valida=C3=A7=C3=A3o=20do=20tamanho?= =?UTF-8?q?=20do=20arquivo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- norma/forms.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/norma/forms.py b/norma/forms.py index 1f80f1b40..dc254ab08 100644 --- a/norma/forms.py +++ b/norma/forms.py @@ -3,12 +3,13 @@ from datetime import datetime from crispy_forms.helper import FormHelper from crispy_forms.layout import Fieldset, Layout from django import forms -from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.forms import ModelForm import crispy_layout_mixin from crispy_layout_mixin import form_actions from materia.models import MateriaLegislativa, TipoMateriaLegislativa +from sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.utils import RANGE_ANOS from .models import NormaJuridica @@ -151,6 +152,13 @@ class NormaJuridicaForm(ModelForm): cleaned_data['materia'] = None return cleaned_data + def clean_texto_integral(self): + texto_integral = self.cleaned_data.get('texto_integral', False) + if texto_integral: + if texto_integral.size > MAX_DOC_UPLOAD_SIZE: + raise ValidationError("Arquivo muito grande. ( > 5mb )") + return texto_integral + def save(self, commit=False): norma = super(NormaJuridicaForm, self).save(commit) norma.timestamp = datetime.now()