Browse Source

Fixes bug #102 (Change ImageField layout)

pull/153/head
Edward Ribeiro 9 years ago
parent
commit
e43155afff
  1. 17
      base/views.py

17
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 %}
<img class="img-responsive"
src="{{ MEDIA_URL }}{{ form.logotipo.value }}">
<input type="submit"
name="remover"
id="remover"
class="button primary"
value="Remover"/>
{% 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,

Loading…
Cancel
Save