Browse Source

Add col mandato_titular na list de Parlamentares

pull/979/head
LeandroRoberto 8 years ago
parent
commit
1febb22566
  1. 13
      sapl/crispy_layout_mixin.py
  2. 20
      sapl/parlamentares/views.py

13
sapl/crispy_layout_mixin.py

@ -1,12 +1,12 @@
from math import ceil from math import ceil
import rtyaml
from crispy_forms.bootstrap import FormActions from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit
from django import template from django import template
from django.utils import formats from django.utils import formats
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
import rtyaml
def heads_and_tails(list_of_lists): def heads_and_tails(list_of_lists):
@ -60,15 +60,16 @@ def get_field_display(obj, fieldname):
field = '' field = ''
try: try:
field = obj._meta.get_field(fieldname) field = obj._meta.get_field(fieldname)
except: except Exception as e:
""" nos casos que o fieldname não é um field_model,
ele pode ser um aggregate, annotate, um property, um manager,
ou mesmo uma método no model.
"""
field = getattr(obj, fieldname) field = getattr(obj, fieldname)
if 'ManyRelatedManager' not in str(type(field))\
and 'RelatedManager' not in str(type(field))\
and 'GenericRelatedObjectManager' not in str(type(field)):
return '', str(field)
verbose_name = str(field.verbose_name)\ verbose_name = str(field.verbose_name)\
if hasattr(field, 'verbose_name') else '' if hasattr(field, 'verbose_name') else ''
if hasattr(field, 'choices') and field.choices: if hasattr(field, 'choices') and field.choices:
value = getattr(obj, 'get_%s_display' % fieldname)() value = getattr(obj, 'get_%s_display' % fieldname)()
else: else:

20
sapl/parlamentares/views.py

@ -1,6 +1,7 @@
from django.contrib import messages from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse, reverse_lazy from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import F
from django.http.response import HttpResponseRedirect from django.http.response import HttpResponseRedirect
from django.utils.datastructures import MultiValueDictKeyError from django.utils.datastructures import MultiValueDictKeyError
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -21,6 +22,7 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa,
NivelInstrucao, Parlamentar, Partido, SessaoLegislativa, NivelInstrucao, Parlamentar, Partido, SessaoLegislativa,
SituacaoMilitar, TipoAfastamento, TipoDependente, Votante) SituacaoMilitar, TipoAfastamento, TipoDependente, Votante)
CargoMesaCrud = CrudAux.build(CargoMesa, 'cargo_mesa') CargoMesaCrud = CrudAux.build(CargoMesa, 'cargo_mesa')
PartidoCrud = CrudAux.build(Partido, 'partidos') PartidoCrud = CrudAux.build(Partido, 'partidos')
SessaoLegislativaCrud = CrudAux.build(SessaoLegislativa, 'sessao_legislativa') SessaoLegislativaCrud = CrudAux.build(SessaoLegislativa, 'sessao_legislativa')
@ -60,8 +62,8 @@ class VotanteView(MasterDetailCrud):
if obj.user: if obj.user:
obj.user.delete() obj.user.delete()
return HttpResponseRedirect( return HttpResponseRedirect(
reverse('sapl.parlamentares:votante_list', reverse('sapl.parlamentares:votante_list',
kwargs={'pk': obj.parlamentar.pk})) kwargs={'pk': obj.parlamentar.pk}))
class FrenteList(MasterDetailCrud): class FrenteList(MasterDetailCrud):
@ -107,7 +109,7 @@ class ProposicaoParlamentarCrud(CrudBaseForListAndDetailExternalAppView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = CrudBaseForListAndDetailExternalAppView\ context = CrudBaseForListAndDetailExternalAppView\
.ListView.get_context_data(self, **kwargs) .ListView.get_context_data(self, **kwargs)
context['title'] = context['title'].replace( context['title'] = context['title'].replace(
'Proposições', 'Matérias') 'Proposições', 'Matérias')
return context return context
@ -264,7 +266,7 @@ class ParlamentarCrud(Crud):
class BaseMixin(Crud.BaseMixin): class BaseMixin(Crud.BaseMixin):
ordered_list = False ordered_list = False
list_field_names = [ list_field_names = [
'avatar_html', 'nome_parlamentar', 'filiacao_atual', 'ativo'] 'avatar_html', 'nome_parlamentar', 'filiacao_atual', 'ativo', 'mandato_titular']
class DetailView(Crud.DetailView): class DetailView(Crud.DetailView):
@ -310,7 +312,8 @@ class ParlamentarCrud(Crud):
legislatura_id = self.take_legislatura_id() legislatura_id = self.take_legislatura_id()
if legislatura_id != 0: if legislatura_id != 0:
return queryset.filter( return queryset.filter(
mandato__legislatura_id=legislatura_id) mandato__legislatura_id=legislatura_id).annotate(
mandato_titular=F('mandato__titular'))
else: else:
try: try:
l = Legislatura.objects.all().order_by( l = Legislatura.objects.all().order_by(
@ -320,10 +323,11 @@ class ParlamentarCrud(Crud):
else: else:
if l is None: if l is None:
return Legislatura.objects.all() return Legislatura.objects.all()
return queryset.filter(mandato__legislatura_id=l) return queryset.filter(mandato__legislatura_id=l).annotate(
mandato_titular=F('mandato__titular'))
def get_headers(self): def get_headers(self):
return ['', _('Parlamentar'), _('Partido'), _('Ativo?')] return ['', _('Parlamentar'), _('Partido'), _('Ativo?'), _('Titular?')]
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
@ -404,7 +408,7 @@ class MesaDiretoraView(FormView):
sessao_legislativa_id=sessao_plenaria.id, sessao_legislativa_id=sessao_plenaria.id,
# parlamentar_id = integrante.parlamentar_id, # parlamentar_id = integrante.parlamentar_id,
cargo_id=cargo.id cargo_id=cargo.id
).exists() ).exists()
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):

Loading…
Cancel
Save