Browse Source

Refactor CasaLegislativa POST

Fix #108 and Fix #110
pull/153/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
44e9b83dcb
  1. 21
      base/views.py

21
base/views.py

@ -181,22 +181,23 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView):
form = CasaLegislativaTabelaAuxForm(request.POST, request.FILES) form = CasaLegislativaTabelaAuxForm(request.POST, request.FILES)
if form.is_valid(): if form.is_valid():
try: casa = CasaLegislativa.objects.first()
casa = CasaLegislativa.objects.first() if casa is not None:
except ObjectDoesNotExist:
casa_save = form.save(commit=False)
else:
if "remover" in request.POST: if "remover" in request.POST:
try: try:
os.unlink(casa.logotipo.path) os.unlink(casa.logotipo.path)
except OSError: except OSError:
pass # Should log this error!!!!! pass # Should log this error!!!!!
casa.logotipo = None casa.logotipo = None
casa_save = CasaLegislativaTabelaAuxForm( casa_save = CasaLegislativaTabelaAuxForm(
request.POST, request.POST,
request.FILES, request.FILES,
instance=casa).save(commit=False) instance=casa
casa_save.save() ).save(commit=False)
casa_save.save()
elif casa is None:
form.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})

Loading…
Cancel
Save