diff --git a/base/views.py b/base/views.py index a829d9b29..72b7853b0 100644 --- a/base/views.py +++ b/base/views.py @@ -9,6 +9,7 @@ from django.views.generic.edit import FormMixin from vanilla import GenericView import sapl +import os from .models import CasaLegislativa @@ -68,6 +69,11 @@ class CasaLegislativaTabelaAuxForm(ModelForm): widget=forms.TextInput( attrs={'class': 'telefone'})) + logotipo = forms.ImageField(label='Logotipo', + required=False, + widget=forms.FileInput + ) + cep = forms.CharField(label='Cep', required=True, widget=forms.TextInput( @@ -138,6 +144,11 @@ class CasaLegislativaTabelaAuxForm(ModelForm): HTML("""{% if form.logotipo.value %} + {% endif %}""", ), row6, row7, @@ -174,6 +185,12 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView): except ObjectDoesNotExist: casa_save = form.save(commit=False) else: + if "remover" in request.POST: + try: + os.unlink(casa.logotipo.path) + except OSError: + pass # Should log this error!!!!! + casa.logotipo = None casa_save = CasaLegislativaTabelaAuxForm( request.POST, request.FILES,