From f7810e8ba59e570c728cba6dfa5da3db34db67a4 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 16 Mar 2016 09:50:32 -0300 Subject: [PATCH] Limita tamanho do logotipo --- base/forms.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/base/forms.py b/base/forms.py index 50161fb8c..22b69092f 100644 --- a/base/forms.py +++ b/base/forms.py @@ -1,6 +1,7 @@ from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Fieldset, Layout from django import forms +from django.core.exceptions import ValidationError from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ @@ -38,6 +39,15 @@ class CasaLegislativaTabelaAuxForm(ModelForm): attrs={'id': 'casa-informacoes'}) } + def clean_logotipo(self): + logotipo = self.cleaned_data.get('logotipo', False) + if logotipo: + if logotipo.size > 2*1024*1024: + raise ValidationError("Imagem muito grande. ( > 2mb )") + return logotipo + else: + raise ValidationError("Não foi possível salvar a imagem.") + def __init__(self, *args, **kwargs): row1 = crispy_layout_mixin.to_row(