Browse Source

Adicionando filtro em convênios por UF

0.3
Camilo Carlos (Estagiario) 15 years ago
parent
commit
09534f26cc
  1. 38
      sigi/admin/filterspecs.py
  2. 2
      sigi/apps/convenios/admin.py
  3. 1
      sigi/apps/convenios/models.py

38
sigi/admin/filterspecs.py

@ -45,7 +45,7 @@ class MunicipioUFFilterSpec(ChoicesFilterSpec):
my_municipio_field.uf_filter = True 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',) list_filter = ('municipio__uf',)
@ -74,6 +74,42 @@ class MunicipioUFFilterSpec(ChoicesFilterSpec):
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'uf_filter', False), FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'uf_filter', False),
MunicipioUFFilterSpec)) 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): class RangeValuesFilterSpec(FilterSpec):
""" """
Author: Willie Gollino (wgollino@yahoo.com) Author: Willie Gollino (wgollino@yahoo.com)

2
sigi/apps/convenios/admin.py

@ -39,7 +39,7 @@ class ConvenioAdmin(admin.ModelAdmin):
inlines = (AnexosInline, EquipamentoPrevistoInline) inlines = (AnexosInline, EquipamentoPrevistoInline)
list_display = ('id', 'casa_legislativa', list_display = ('id', 'casa_legislativa',
'num_processo_sf', 'data_adesao', 'projeto') 'num_processo_sf', 'data_adesao', 'projeto')
list_filter = ('projeto',) list_filter = ('projeto','casa_legislativa')
date_hierarchy = 'data_adesao' date_hierarchy = 'data_adesao'
ordering = ('-id',) ordering = ('-id',)
raw_id_fields = ('casa_legislativa',) raw_id_fields = ('casa_legislativa',)

1
sigi/apps/convenios/models.py

@ -15,6 +15,7 @@ class Convenio(models.Model):
'casas.CasaLegislativa', 'casas.CasaLegislativa',
verbose_name='Casa Legislativa' verbose_name='Casa Legislativa'
) )
casa_legislativa.uf_filter = True
num_processo_sf = models.CharField( num_processo_sf = models.CharField(
'número do processo SF', 'número do processo SF',
max_length=11, max_length=11,

Loading…
Cancel
Save