Browse Source

Make QA (almost) happy

pull/153/head
Edward Ribeiro 9 years ago
parent
commit
06ab6dd0ce
  1. 21
      base/views.py
  2. 13
      compilacao/views.py
  3. 27
      parlamentares/views.py

21
base/views.py

@ -1,3 +1,5 @@
import os
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, ButtonHolder, Fieldset, Layout, Submit
from django import forms
@ -9,7 +11,6 @@ from django.views.generic.edit import FormMixin
from vanilla import GenericView
import sapl
import os
from .models import CasaLegislativa
@ -186,15 +187,15 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView):
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,
instance=casa).save(commit=False)
try:
os.unlink(casa.logotipo.path)
except OSError:
pass # Should log this error!!!!!
casa.logotipo = None
casa_save = CasaLegislativaTabelaAuxForm(
request.POST,
request.FILES,
instance=casa).save(commit=False)
casa_save.save()
return self.form_valid(form)
else:

13
compilacao/views.py

@ -1,6 +1,6 @@
import sys
from collections import OrderedDict
from datetime import datetime, timedelta
import sys
from braces.views import FormMessagesMixin
from django import forms
@ -21,15 +21,14 @@ from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django.views.generic.list import ListView
from compilacao import utils
from compilacao.forms import NotaForm, TaForm, TipoTaForm, VideForm,\
PublicacaoForm
from compilacao.forms import (NotaForm, PublicacaoForm, TaForm, TipoTaForm,
VideForm)
from compilacao.models import (Dispositivo, Nota,
PerfilEstruturalTextoArticulado,
PerfilEstruturalTextoArticulado, Publicacao,
TextoArticulado, TipoDispositivo, TipoNota,
TipoPublicacao, TipoTextoArticulado, TipoVide,
VeiculoPublicacao, Vide, Publicacao)
from compilacao.utils import build_crud, NO_ENTRIES_MSG
VeiculoPublicacao, Vide)
from compilacao.utils import NO_ENTRIES_MSG, build_crud
DISPOSITIVO_SELECT_RELATED = (
'tipo_dispositivo',

27
parlamentares/views.py

@ -1,3 +1,4 @@
import os
from re import sub
from crispy_forms.helper import FormHelper
@ -12,7 +13,6 @@ from django.views.generic.edit import FormMixin
from vanilla import GenericView
import sapl
import os
from sapl.crud import build_crud
from .models import (CargoMesa, Coligacao, ComposicaoMesa, Dependente,
@ -274,9 +274,9 @@ class ParlamentaresForm (ModelForm):
attrs={'class': 'telefone'}))
fotografia = forms.ImageField(label='Fotografia',
required=False,
widget=forms.FileInput
)
required=False,
widget=forms.FileInput
)
class Meta:
model = Parlamentar
@ -363,7 +363,7 @@ class ParlamentaresForm (ModelForm):
Fieldset('Cadastro do Parlamentar',
row1, row2, row3, row4, row5,
row6, row7, row8, row9, row10,
row11, row12, row13,
row11, row12, row13,
HTML("""{% if form.fotografia.value %}
<img class="img-responsive"
src="{{ MEDIA_URL }}{{ form.fotografia.value }}">
@ -373,7 +373,7 @@ class ParlamentaresForm (ModelForm):
class="button primary"
value="Remover"/>
{% endif %}""", ),
row14,
row14,
ButtonHolder(
Submit('submit', 'Salvar',
css_class='button primary'),
@ -466,14 +466,13 @@ class ParlamentaresEditarView(FormMixin, GenericView):
Mandato.objects.get(parlamentar=parlamentar).delete()
parlamentar.delete()
elif "remover" in request.POST:
try:
os.unlink(parlamentar.fotografia.path)
except OSError:
pass # Should log this error!!!!!
parlamentar = form.save(commit=False)
parlamentar.fotografia = None
parlamentar.save()
try:
os.unlink(parlamentar.fotografia.path)
except OSError:
pass # Should log this error!!!!!
parlamentar = form.save(commit=False)
parlamentar.fotografia = None
parlamentar.save()
return self.form_valid(form)
else:

Loading…
Cancel
Save