Browse Source

Corrigindo filterspec para selecionar por estado em convênios

diagnosticos
Camilo Carlos (Estagiario) 15 years ago
parent
commit
904e79f4e4
  1. 52
      sigi/admin/filterspecs.py
  2. 2
      sigi/apps/convenios/models.py

52
sigi/admin/filterspecs.py

@ -40,13 +40,13 @@ class AlphabeticFilterSpec(ChoicesFilterSpec):
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'alphabetic_filter', False), FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'alphabetic_filter', False),
AlphabeticFilterSpec)) AlphabeticFilterSpec))
class UFFilterSpec(ChoicesFilterSpec): class AbstractFilterSpec(ChoicesFilterSpec):
""" """
This is an abstract class and customs filters by 'Uf' have to extend this class. This is an abstract class and customs filters by 'Uf' have to extend this class.
""" """
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
def __init__(self, f, request, params, model, model_admin): def __init__(self, f, request, params, model, model_admin):
super(UFFilterSpec, self).__init__(f, request, params, model, super(AbstractFilterSpec, self).__init__(f, request, params, model,
model_admin) model_admin)
def choices(self, cl): def choices(self, cl):
@ -57,11 +57,8 @@ class UFFilterSpec(ChoicesFilterSpec):
yield {'selected': smart_unicode(val.codigo_ibge) == self.lookup_val, yield {'selected': smart_unicode(val.codigo_ibge) == self.lookup_val,
'query_string': cl.get_query_string({self.lookup_kwarg: val.codigo_ibge}), 'query_string': cl.get_query_string({self.lookup_kwarg: val.codigo_ibge}),
'display': val.nome} 'display': val.nome}
def title(self):
return _('UF') % \
{'field_name': self.field.verbose_name}
class MunicipioUFFilterSpec(UFFilterSpec): class MunicipioUFFilterSpec(AbstractFilterSpec):
""" """
Usage: Usage:
@ -79,13 +76,16 @@ class MunicipioUFFilterSpec(UFFilterSpec):
self.lookup_kwarg = '%s__uf__codigo_ibge__exact' % f.name self.lookup_kwarg = '%s__uf__codigo_ibge__exact' % f.name
self.lookup_val = request.GET.get(self.lookup_kwarg, None) self.lookup_val = request.GET.get(self.lookup_kwarg, None)
self.lookup_choices = UnidadeFederativa.objects.all().order_by('nome') self.lookup_choices = UnidadeFederativa.objects.all().order_by('nome')
def title(self):
return _('UF') % \
{'field_name': self.field.verbose_name}
# registering the filter # registering the filter
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(UFFilterSpec): class ConvenioUFFilterSpec(AbstractFilterSpec):
""" """
Usage: Usage:
@ -101,10 +101,48 @@ class ConvenioUFFilterSpec(UFFilterSpec):
self.lookup_kwarg = '%s__municipio__uf__codigo_ibge__exact' % f.name self.lookup_kwarg = '%s__municipio__uf__codigo_ibge__exact' % f.name
self.lookup_val = request.GET.get(self.lookup_kwarg, None) self.lookup_val = request.GET.get(self.lookup_kwarg, None)
self.lookup_choices = UnidadeFederativa.objects.all().order_by('nome') self.lookup_choices = UnidadeFederativa.objects.all().order_by('nome')
def title(self):
return _('UF') % \
{'field_name': self.field.verbose_name}
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'convenio_uf_filter', False), FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'convenio_uf_filter', False),
ConvenioUFFilterSpec)) ConvenioUFFilterSpec))
class MunicipioRegiaoFilterSpec(AbstractFilterSpec):
"""
Usage:
my_municipio_field.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(MunicipioRegiaoFilterSpec, self).__init__(f, request, params, model,
model_admin)
self.lookup_kwarg = '%s__uf__regiao__exact' % f.name
self.lookup_val = request.GET.get(self.lookup_kwarg, None)
self.lookup_choices = UnidadeFederativa.REGIAO_CHOICES
def title(self):
return _('UF') % \
{'field_name': self.field.verbose_name}
# registering the filter
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'regiao_filter', False),
MunicipioRegiaoFilterSpec))
class ConvenioRegiaoFilterSpec(AbstractFilterSpec):
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__regiao__exact' % f.name
self.lookup_val = request.GET.get(self.lookup_kwarg, None)
self.lookup_choices = UnidadeFederativa.REGIAO_CHOICES
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'convenio_regiao_filter', False), ConvenioRegiaoFilterSpec))
class RangeValuesFilterSpec(FilterSpec): class RangeValuesFilterSpec(FilterSpec):
""" """
Author: Willie Gollino (wgollino@yahoo.com) Author: Willie Gollino (wgollino@yahoo.com)

2
sigi/apps/convenios/models.py

@ -15,7 +15,7 @@ class Convenio(models.Model):
'casas.CasaLegislativa', 'casas.CasaLegislativa',
verbose_name='Casa Legislativa' verbose_name='Casa Legislativa'
) )
casa_legislativa.uf_filter = True casa_legislativa.convenio_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