Browse Source

Acrescentado filtro por tipo de serviço na changelist das casas atendidas

stable/1.0
Sesostris Vieira 12 years ago
parent
commit
85c76d0709
  1. 37
      sigi/admin/filterspecs.py
  2. 1
      sigi/apps/casas/models.py
  3. 4
      sigi/apps/servicos/admin.py

37
sigi/admin/filterspecs.py

@ -4,6 +4,7 @@ from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
from sigi.apps.contatos.models import UnidadeFederativa
from abc import ABCMeta
from apps.servicos.models import TipoServico
class IsActiveFilterSpec(BooleanFieldFilterSpec):
"""
@ -210,3 +211,39 @@ class RangeValuesFilterSpec(FilterSpec):
FilterSpec.filter_specs.insert(-1, (lambda f: hasattr(f, 'list_filter_range'),
RangeValuesFilterSpec))
class TipoServicoFilterSpec(ChoicesFilterSpec):
"""
Usage:
tipo_servico_field.ts_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(TipoServicoFilterSpec, self).__init__(f, request, params, model,
model_admin)
self.lookup_kwarg = 'servico__tipo_servico__id__exact'
self.lookup_val = request.GET.get(self.lookup_kwarg, None)
self.lookup_choices = TipoServico.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.id) == self.lookup_val,
'query_string': cl.get_query_string({self.lookup_kwarg: val.id}),
'display': val.nome}
def title(self):
return _('Tipo de servico')
# registering the filter
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'ts_filter', False),
TipoServicoFilterSpec))

1
sigi/apps/casas/models.py

@ -40,6 +40,7 @@ class CasaLegislativa(models.Model):
observacoes = models.TextField(u'observações', blank=True)
num_parlamentares = models.PositiveIntegerField('Número de parlamentares')
codigo_interlegis = models.CharField('Código Interlegis', max_length=3, blank=True)
codigo_interlegis.ts_filter = True
# Informações de contato
logradouro = models.CharField(

4
sigi/apps/servicos/admin.py

@ -126,14 +126,14 @@ class CasaAtendidaAdmin(admin.ModelAdmin):
,)
readonly_fields = ('nome', 'logradouro', 'bairro', 'municipio', 'cep')
inlines = (ContatosInline,)
list_filter = ('tipo', 'municipio', )
list_filter = ('tipo', 'codigo_interlegis', 'municipio', )
search_fields = ('search_text','cnpj', 'bairro', 'logradouro',
'cep', 'municipio__nome', 'municipio__uf__nome',
'municipio__codigo_ibge', 'pagina_web', 'observacoes')
def lookup_allowed(self, lookup, value):
return super(CasaAtendidaAdmin, self).lookup_allowed(lookup, value) or \
lookup in ['municipio__uf__codigo_ibge__exact']
lookup in ['municipio__uf__codigo_ibge__exact', 'servico__tipo_servico__id__exact', ]
def change_view(self, request, object_id, extra_context=None):
# Se a Casa ainda não é atendida, gerar o código interlegis para ela

Loading…
Cancel
Save