Browse Source

Inclusão de lista de serviços filtrável por tipo e UF

stable/1.0
Sesostris Vieira 12 years ago
parent
commit
b00c249a4a
  1. 27
      sigi/admin/filterspecs.py
  2. 18
      sigi/apps/servicos/admin.py
  3. 2
      sigi/apps/servicos/models.py
  4. 4
      sigi/templates/admin/servicos/servico/change_list.html

27
sigi/admin/filterspecs.py

@ -107,6 +107,33 @@ class MunicipioUFFilterSpec(AbstractFilterSpec):
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 CasaUFFilterSpec(AbstractFilterSpec):
"""
Usage:
my_casa_legislativa_field.casa_uf_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(CasaUFFilterSpec, 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 title(self):
return _('UF') % \
{'field_name': self.field.verbose_name}
# registering the filter
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'casa_uf_filter', False),
CasaUFFilterSpec))
class ConvenioUFFilterSpec(AbstractFilterSpec): class ConvenioUFFilterSpec(AbstractFilterSpec):
""" """
Usage: Usage:

18
sigi/apps/servicos/admin.py

@ -48,7 +48,7 @@ class TipoServicoAdmin(admin.ModelAdmin):
class ServicoAdmin(admin.ModelAdmin): class ServicoAdmin(admin.ModelAdmin):
form = ServicoFormAdmin form = ServicoFormAdmin
list_display = ('casa_legislativa', 'tipo_servico', 'hospedagem_interlegis', 'data_ativacao', 'data_desativacao',) list_display = ('casa_legislativa','getUf', 'tipo_servico', 'hospedagem_interlegis', 'data_ativacao', 'data_desativacao',)
fieldsets = (( None, { fieldsets = (( None, {
'fields': ('casa_legislativa', 'data_ativacao',) 'fields': ('casa_legislativa', 'data_ativacao',)
}), }),
@ -62,9 +62,23 @@ class ServicoAdmin(admin.ModelAdmin):
'fields': ('data_alteracao', 'data_desativacao', 'motivo_desativacao',) 'fields': ('data_alteracao', 'data_desativacao', 'motivo_desativacao',)
})) }))
readonly_fields = ('casa_legislativa', 'data_ativacao', 'data_alteracao') readonly_fields = ('casa_legislativa', 'data_ativacao', 'data_alteracao')
list_filter = ('tipo_servico', 'hospedagem_interlegis', 'casa_legislativa')
list_display_links = []
ordering = ('casa_legislativa__municipio__uf', 'casa_legislativa', 'tipo_servico',)
actions = None
inlines = (LogServicoInline,) inlines = (LogServicoInline,)
def getUf(self, obj):
return '%s' % (obj.casa_legislativa.municipio.uf)
getUf.short_description = 'UF'
getUf.admin_order_field = 'casa_legislativa__municipio__uf'
def lookup_allowed(self, lookup, value):
return super(ServicoAdmin, self).lookup_allowed(lookup, value) or \
lookup in ['casa_legislativa__municipio__uf__codigo_ibge__exact']
def add_view(self, request, form_url='', extra_context=None): def add_view(self, request, form_url='', extra_context=None):
id_casa = request.GET.get('id_casa', None) id_casa = request.GET.get('id_casa', None)

2
sigi/apps/servicos/models.py

@ -42,6 +42,8 @@ class Servico(models.Model):
data_desativacao = models.DateField('Data de desativação', blank=True, null=True) data_desativacao = models.DateField('Data de desativação', blank=True, null=True)
motivo_desativacao = models.TextField('Motivo da desativação', blank=True) motivo_desativacao = models.TextField('Motivo da desativação', blank=True)
casa_legislativa.casa_uf_filter = True
def __unicode__(self): def __unicode__(self):
return "%s (%s)" % (self.tipo_servico.nome, 'ativo' if self.data_desativacao is None else 'Desativado') return "%s (%s)" % (self.tipo_servico.nome, 'ativo' if self.data_desativacao is None else 'Desativado')

4
sigi/templates/admin/servicos/servico/change_list.html

@ -0,0 +1,4 @@
{% extends "admin/change_list.html" %}
{% block object-tools %}
{% endblock %}
Loading…
Cancel
Save