Browse Source

Limite o tamanho da foto para 2mb

pull/269/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
committed by Edward Ribeiro
parent
commit
e91b7e7c1a
  1. 10
      parlamentares/forms.py
  2. 1
      parlamentares/views.py

10
parlamentares/forms.py

@ -1,6 +1,7 @@
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Fieldset, Layout, Submit from crispy_forms.layout import HTML, Fieldset, Layout, Submit
from django import forms from django import forms
from django.core.exceptions import ValidationError
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -30,6 +31,15 @@ class ParlamentaresForm (ModelForm):
) )
) )
def clean_fotografia(self):
fotografia = self.cleaned_data.get('fotografia', False)
if fotografia:
if fotografia.size > 2*1024*1024:
raise ValidationError('Imagem muito grande. ( > 2mb )')
return fotografia
else:
raise ValidationError('Não foi possível salvar a imagem.')
class Meta: class Meta:
model = Parlamentar model = Parlamentar
fields = ['nome_parlamentar', fields = ['nome_parlamentar',

1
parlamentares/views.py

@ -185,6 +185,7 @@ class ParlamentaresCadastroView(CreateView):
return context return context
def form_valid(self, form): def form_valid(self, form):
import ipdb; ipdb.set_trace()
form.save() form.save()
mandato = Mandato() mandato = Mandato()
mandato.parlamentar = form.instance mandato.parlamentar = form.instance

Loading…
Cancel
Save