From 09534f26cce5156f57fdbd72363f3e67d0ebb89f Mon Sep 17 00:00:00 2001 From: "Camilo Carlos (Estagiario)" Date: Thu, 27 May 2010 20:18:08 +0000 Subject: [PATCH] =?UTF-8?q?Adicionando=20filtro=20em=20conv=C3=AAnios=20po?= =?UTF-8?q?r=20UF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/admin/filterspecs.py | 38 ++++++++++++++++++++++++++++++++++- sigi/apps/convenios/admin.py | 2 +- sigi/apps/convenios/models.py | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/sigi/admin/filterspecs.py b/sigi/admin/filterspecs.py index d926dab..74a67d7 100644 --- a/sigi/admin/filterspecs.py +++ b/sigi/admin/filterspecs.py @@ -45,7 +45,7 @@ class MunicipioUFFilterSpec(ChoicesFilterSpec): my_municipio_field.uf_filter = True - On Django 1.2 you will can specify a lookup on admin filters. Example: + On Django 1.3 you will can specify a lookup on admin filters. Example: list_filter = ('municipio__uf',) @@ -74,6 +74,42 @@ class MunicipioUFFilterSpec(ChoicesFilterSpec): FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'uf_filter', False), MunicipioUFFilterSpec)) +class ConvenioUFFilterSpec(ChoicesFilterSpec): + """ + Usage: + + municipio.uf_filter = True + + On Django 1.3 you will can specify a lookup on admin filters. Example: + + list_filter = ('municipio__uf',) + + """ + + def __init__(self, f, request, params, model, model_admin): + super(ConvenioUFFilterSpec, self).__init__(f, request, params, model, + model_admin) + self.lookup_kwarg = '%s__municipio__uf__codigo_ibge__exact' % f.name + self.lookup_val = request.GET.get(self.lookup_kwarg, None) + self.lookup_choices = UnidadeFederativa.objects.all().order_by('nome') + + 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.codigo_ibge) == self.lookup_val, + 'query_string': cl.get_query_string({self.lookup_kwarg: val.codigo_ibge}), + 'display': val.nome} + def title(self): + return _('UF') % \ + {'field_name': self.field.verbose_name} + +# registering the filter +FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'uf_filter', False), + ConvenioUFFilterSpec)) + + class RangeValuesFilterSpec(FilterSpec): """ Author: Willie Gollino (wgollino@yahoo.com) diff --git a/sigi/apps/convenios/admin.py b/sigi/apps/convenios/admin.py index 120ce98..75af0e5 100644 --- a/sigi/apps/convenios/admin.py +++ b/sigi/apps/convenios/admin.py @@ -39,7 +39,7 @@ class ConvenioAdmin(admin.ModelAdmin): inlines = (AnexosInline, EquipamentoPrevistoInline) list_display = ('id', 'casa_legislativa', 'num_processo_sf', 'data_adesao', 'projeto') - list_filter = ('projeto',) + list_filter = ('projeto','casa_legislativa') date_hierarchy = 'data_adesao' ordering = ('-id',) raw_id_fields = ('casa_legislativa',) diff --git a/sigi/apps/convenios/models.py b/sigi/apps/convenios/models.py index 2512dff..60d64ef 100644 --- a/sigi/apps/convenios/models.py +++ b/sigi/apps/convenios/models.py @@ -15,6 +15,7 @@ class Convenio(models.Model): 'casas.CasaLegislativa', verbose_name='Casa Legislativa' ) + casa_legislativa.uf_filter = True num_processo_sf = models.CharField( 'nĂºmero do processo SF', max_length=11,