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 from vanilla import GenericView
import sapl import sapl
import os
from .models import CasaLegislativa from .models import CasaLegislativa
@ -68,6 +69,11 @@ class CasaLegislativaTabelaAuxForm(ModelForm):
widget=forms.TextInput( widget=forms.TextInput(
attrs={'class': 'telefone'})) attrs={'class': 'telefone'}))
logotipo = forms.ImageField(label='Logotipo',
required=False,
widget=forms.FileInput
)
cep = forms.CharField(label='Cep', cep = forms.CharField(label='Cep',
required=True, required=True,
widget=forms.TextInput( widget=forms.TextInput(
@ -138,6 +144,11 @@ class CasaLegislativaTabelaAuxForm(ModelForm):
HTML("""{% if form.logotipo.value %} HTML("""{% if form.logotipo.value %}
<img class="img-responsive" <img class="img-responsive"
src="{{ MEDIA_URL }}{{ form.logotipo.value }}"> src="{{ MEDIA_URL }}{{ form.logotipo.value }}">
<input type="submit"
name="remover"
id="remover"
class="button primary"
value="Remover"/>
{% endif %}""", ), {% endif %}""", ),
row6, row6,
row7, row7,
@ -174,6 +185,12 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView):
except ObjectDoesNotExist: except ObjectDoesNotExist:
casa_save = form.save(commit=False) casa_save = form.save(commit=False)
else: 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( casa_save = CasaLegislativaTabelaAuxForm(
request.POST, request.POST,
request.FILES, request.FILES,

Loading…
Cancel
Save