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. 11
      base/views.py

11
base/views.py

@ -181,11 +181,8 @@ 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()
except ObjectDoesNotExist: if casa is not None:
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)
@ -195,8 +192,12 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView):
casa_save = CasaLegislativaTabelaAuxForm( casa_save = CasaLegislativaTabelaAuxForm(
request.POST, request.POST,
request.FILES, request.FILES,
instance=casa).save(commit=False) instance=casa
).save(commit=False)
casa_save.save() 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