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. 12
      sapl/parlamentares/views.py

13
sapl/crispy_layout_mixin.py

@ -1,12 +1,12 @@
from math import ceil
import rtyaml
from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit
from django import template
from django.utils import formats
from django.utils.translation import ugettext as _
import rtyaml
def heads_and_tails(list_of_lists):
@ -60,15 +60,16 @@ def get_field_display(obj, fieldname):
field = ''
try:
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)
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)\
if hasattr(field, 'verbose_name') else ''
if hasattr(field, 'choices') and field.choices:
value = getattr(obj, 'get_%s_display' % fieldname)()
else:

12
sapl/parlamentares/views.py

@ -1,6 +1,7 @@
from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import F
from django.http.response import HttpResponseRedirect
from django.utils.datastructures import MultiValueDictKeyError
from django.utils.translation import ugettext_lazy as _
@ -21,6 +22,7 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa,
NivelInstrucao, Parlamentar, Partido, SessaoLegislativa,
SituacaoMilitar, TipoAfastamento, TipoDependente, Votante)
CargoMesaCrud = CrudAux.build(CargoMesa, 'cargo_mesa')
PartidoCrud = CrudAux.build(Partido, 'partidos')
SessaoLegislativaCrud = CrudAux.build(SessaoLegislativa, 'sessao_legislativa')
@ -264,7 +266,7 @@ class ParlamentarCrud(Crud):
class BaseMixin(Crud.BaseMixin):
ordered_list = False
list_field_names = [
'avatar_html', 'nome_parlamentar', 'filiacao_atual', 'ativo']
'avatar_html', 'nome_parlamentar', 'filiacao_atual', 'ativo', 'mandato_titular']
class DetailView(Crud.DetailView):
@ -310,7 +312,8 @@ class ParlamentarCrud(Crud):
legislatura_id = self.take_legislatura_id()
if legislatura_id != 0:
return queryset.filter(
mandato__legislatura_id=legislatura_id)
mandato__legislatura_id=legislatura_id).annotate(
mandato_titular=F('mandato__titular'))
else:
try:
l = Legislatura.objects.all().order_by(
@ -320,10 +323,11 @@ class ParlamentarCrud(Crud):
else:
if l is None:
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):
return ['', _('Parlamentar'), _('Partido'), _('Ativo?')]
return ['', _('Parlamentar'), _('Partido'), _('Ativo?'), _('Titular?')]
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

Loading…
Cancel
Save