Browse Source

Adicionado filtro e ordenação por UF na lista de diagnosticos (administração)

stable/1.0
Sesostris Vieira 12 years ago
parent
commit
422dc88ef7
  1. 35
      sigi/admin/filterspecs.py
  2. 10
      sigi/apps/diagnosticos/admin.py
  3. 4
      sigi/apps/diagnosticos/models.py

35
sigi/admin/filterspecs.py

@ -6,6 +6,7 @@ from sigi.apps.contatos.models import UnidadeFederativa
from abc import ABCMeta
from apps.servicos.models import TipoServico
from apps.convenios.models import Projeto
from apps.casas.models import TipoCasaLegislativa
class IsActiveFilterSpec(BooleanFieldFilterSpec):
"""
@ -135,6 +136,40 @@ class CasaUFFilterSpec(AbstractFilterSpec):
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'casa_uf_filter', False),
CasaUFFilterSpec))
class CasaTipoFilterSpec(ChoicesFilterSpec):
"""
Usage:
my_casa_legislativa_field.casa_tipo_filter = True
On Django 1.3 you will can specify a lookup on admin filters. Example:
list_filter = ('casa_legislativa__municipio__uf',)
"""
def __init__(self, f, request, params, model, model_admin):
super(CasaTipoFilterSpec, self).__init__(f, request, params, model,
model_admin)
self.lookup_kwarg = '%s__tipo__id__exact' % f.name
self.lookup_val = request.GET.get(self.lookup_kwarg, None)
self.lookup_choices = TipoCasaLegislativa.objects.all()
def title(self):
return _('Tipo de Casa Legislativa') % {'field_name': self.field.verbose_name}
def choices(self, cl):
yield {'selected': self.lookup_val is None,
'query_string': cl.get_query_string({}, [self.lookup_kwarg]),
'display': _('All')}
for val in self.lookup_choices:
yield {'selected': smart_unicode(val.id) == self.lookup_val,
'query_string': cl.get_query_string({self.lookup_kwarg: val.id}),
'display': val.nome}
# registering the filter
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'casa_tipo_filter', False),
CasaTipoFilterSpec))
class ConvenioUFFilterSpec(AbstractFilterSpec):
"""
Usage:

10
sigi/apps/diagnosticos/admin.py

@ -48,8 +48,8 @@ class DiagnosticoAdmin(BaseEntityAdmin):
actions = [publicar_diagnostico, despublicar_diagnostico]
inlines = (EquipeInline, AnexosInline)
search_fields = ('casa_legislativa__nome',)
list_display = ('casa_legislativa','getUf', 'data_visita_inicio', 'data_visita_fim', 'responsavel', 'publicado')
list_filter = ('publicado', 'data_publicacao', 'data_visita_inicio', 'data_visita_fim')
list_display = ('casa_legislativa','get_uf', 'data_visita_inicio', 'data_visita_fim', 'responsavel', 'publicado')
list_filter = ('publicado', 'casa_legislativa', 'data_publicacao', 'data_visita_inicio', 'data_visita_fim')
raw_id_fields = ('casa_legislativa',)
ordering = ('casa_legislativa',)
@ -71,10 +71,10 @@ class DiagnosticoAdmin(BaseEntityAdmin):
'classes': ['collapse']
}))
def getUf(self, obj):
def get_uf(self, obj):
return '%s' % (obj.casa_legislativa.municipio.uf)
getUf.short_description = 'UF'
get_uf.short_description = 'UF'
get_uf.admin_order_field = 'casa_legislativa__municipio__uf__nome'
class EscolhaAdmin(admin.ModelAdmin):
search_fields = ('title',)

4
sigi/apps/diagnosticos/models.py

@ -18,8 +18,8 @@ class Diagnostico(BaseEntity):
# campo de busca em caixa baixa e sem acento
search_text = SearchField(field_names=['casa_legislativa'])
casa_legislativa.convenio_uf_filter = True
casa_legislativa.convenio_cl_tipo_filter = True
casa_legislativa.casa_uf_filter = True
# casa_legislativa.casa_tipo_filter = True
data_visita_inicio = models.DateField(
u'data inicial da visita',
null=True,

Loading…
Cancel
Save