|
@ -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', |
|
|