Browse Source

Reverting overwritten changes made by 926bf0cad8

pull/98/head
Edward Ribeiro 9 years ago
parent
commit
529765399d
  1. 21
      base/views.py

21
base/views.py

@ -1,6 +1,6 @@
import sapl import sapl
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import ButtonHolder, Fieldset, Layout, Submit from crispy_forms.layout import ButtonHolder, HTML, Fieldset, Layout, Submit
from django import forms from django import forms
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
@ -11,6 +11,8 @@ from vanilla import GenericView
from .models import CasaLegislativa from .models import CasaLegislativa
from sapl import settings
class HelpView(TemplateView): class HelpView(TemplateView):
# XXX treat non existing template as a 404!!!! # XXX treat non existing template as a 404!!!!
@ -76,7 +78,7 @@ class CasaLegislativaTabelaAuxForm(ModelForm):
fax = forms.CharField(label='Fax', fax = forms.CharField(label='Fax',
required=False, required=False,
widget=forms.TextInput( widget=forms.TextInput(
attrs={'class': 'telefone'})) attrs={'class': 'telefone'}))
class Meta: class Meta:
@ -135,6 +137,10 @@ class CasaLegislativaTabelaAuxForm(ModelForm):
row3, row3,
row4, row4,
row5, row5,
HTML("""{% if form.logotipo.value %}
<img class="img-responsive"
src="{{ MEDIA_URL }}{{ form.logotipo.value }}">
{% endif %}""", ),
row6, row6,
row7, row7,
row8, row8,
@ -162,7 +168,7 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView):
return self.render_to_response({'form': form}) return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = CasaLegislativaTabelaAuxForm(request.POST or request.FILES) form = CasaLegislativaTabelaAuxForm(request.POST, request.FILES)
if form.is_valid(): if form.is_valid():
try: try:
@ -171,16 +177,11 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView):
casa_save = form.save(commit=False) casa_save = form.save(commit=False)
else: else:
casa_save = CasaLegislativaTabelaAuxForm( casa_save = CasaLegislativaTabelaAuxForm(
request.POST, instance=casa) request.POST, request.FILES, instance=casa).save(commit=False)
if 'logotipo' in request.FILES:
casa_save.logotipo = request.FILES['logotipo']
casa_save.save() casa_save.save()
return self.form_valid(form) return self.form_valid(form)
else: else:
return self.render_to_response({'form': form}) return self.render_to_response({'form': form})
def get_success_url(self): def get_success_url(self):
return reverse('casa_legislativa') return reverse('casa_legislativa')
Loading…
Cancel
Save