From 422dc88ef7ff90a15f925544acf93cf9306e9094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 23 May 2013 16:23:58 -0300 Subject: [PATCH] =?UTF-8?q?Adicionado=20filtro=20e=20ordena=C3=A7=C3=A3o?= =?UTF-8?q?=20por=20UF=20na=20lista=20de=20diagnosticos=20(administra?= =?UTF-8?q?=C3=A7=C3=A3o)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/admin/filterspecs.py | 35 ++++++++++++++++++++++++++++++++ sigi/apps/diagnosticos/admin.py | 10 ++++----- sigi/apps/diagnosticos/models.py | 4 ++-- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/sigi/admin/filterspecs.py b/sigi/admin/filterspecs.py index 49645fe..73c2878 100644 --- a/sigi/admin/filterspecs.py +++ b/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: diff --git a/sigi/apps/diagnosticos/admin.py b/sigi/apps/diagnosticos/admin.py index ef7e911..c22fd57 100644 --- a/sigi/apps/diagnosticos/admin.py +++ b/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',) diff --git a/sigi/apps/diagnosticos/models.py b/sigi/apps/diagnosticos/models.py index 791e1b7..d15ee8e 100644 --- a/sigi/apps/diagnosticos/models.py +++ b/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,