Browse Source

Adicionados filtros por UF e por data de entrega no changelist de Planos Diretores

stable/1.0
Sesostris Vieira 12 years ago
parent
commit
011c16de39
  1. 36
      sigi/apps/metas/admin.py
  2. 1
      sigi/apps/metas/models.py
  3. 19
      sigi/templates/admin/metas/planodiretor/change_list.html

36
sigi/apps/metas/admin.py

@ -8,7 +8,39 @@ class MetaAdmin(admin.ModelAdmin):
list_filter = ('projeto',)
class PlanoDiretorAdmin(admin.ModelAdmin):
list_display = ('projeto', 'casa_legislativa', 'status', 'data_entrega', 'data_implantacao',)
list_display = ('projeto', 'casa_legislativa', 'get_uf', 'status', 'data_entrega', 'data_implantacao',)
fields = ('projeto', 'casa_legislativa', 'status', 'data_entrega', 'data_implantacao',)
raw_id_fields = ('casa_legislativa',)
list_filter = ('projeto', 'status',)
list_filter = ('projeto', 'status', 'casa_legislativa', )
def get_uf(self, obj):
return obj.casa_legislativa.municipio.uf.nome
get_uf.short_description = u"UF"
get_uf.admin_order_field = 'casa_legislativa__municipio__uf__nome'
def lookup_allowed(self, lookup, value):
return super(PlanoDiretorAdmin, self).lookup_allowed(lookup, value) or \
lookup in ['casa_legislativa__municipio__uf__codigo_ibge__exact']
def changelist_view(self, request, extra_context=None):
import re
request.GET._mutable=True
if 'data_entrega__gte' in request.GET:
value = request.GET.get('data_entrega__gte','')
if value == '':
del request.GET['data_entrega__gte']
elif re.match('^\d*$', value): # Year only
request.GET['data_entrega__gte'] = "%s-01-01" % value #Complete with january 1st
elif re.match('^\d*\D\d*$', value): # Year and month
request.GET['data_entrega__gte'] = '%s-01' % value #Complete with 1st day of month
if 'data_entrega__lte' in request.GET:
value = request.GET.get('data_entrega__lte','')
if value == '':
del request.GET['data_entrega__lte']
elif re.match('^\d*$', value): # Year only
request.GET['data_entrega__lte'] = "%s-01-01" % value #Complete with january 1st
elif re.match('^\d*\D\d*$', value): # Year and month
request.GET['data_entrega__lte'] = '%s-01' % value #Complete with 1st day of month
request.GET._mutable=False
return super(PlanoDiretorAdmin, self).changelist_view(request, extra_context)

1
sigi/apps/metas/models.py

@ -114,6 +114,7 @@ class PlanoDiretor(models.Model):
)
projeto = models.ForeignKey(Projeto, verbose_name=u'Projeto')
casa_legislativa = models.ForeignKey(CasaLegislativa, verbose_name=u'Casa legislativa')
casa_legislativa.casa_uf_filter = True
status = models.CharField(u'Status', max_length=1, choices=STATUS_CHOICE, default='E')
data_entrega = models.DateField(u'Data de entrega', blank=True, null=True)
data_implantacao = models.DateField(u'Data de implantação', blank=True, null=True)

19
sigi/templates/admin/metas/planodiretor/change_list.html

@ -0,0 +1,19 @@
{% extends "admin/change_list.html" %}
{% load i18n reporting_tags admin_list %}
{% block search %}
<div id="toolbar">
<form id="changelist-search" action="" method="get">
<div><!-- DIV needed for valid HTML -->
<label for="searchbar"><img src="/sigi/admin_media/img/admin/icon_searchbox.png" alt="Search" /></label>
<input type="text" size="40" name="q" value="" id="searchbar" />
<label for="data_entrega__gte">Entregues a partir de:</label>
<input type="text" size="10" name="data_entrega__gte" value="" id="data_entrega__gte" class="vDateField"/>
<label for="data_entrega__lte">até:</label>
<input type="text" size="10" name="data_entrega__lte" value="" id="data_entrega__lte" />
<input type="submit" value="Pesquisar" />
Datas podem ser: Um ano (aaaa), um mês (aaaa-mm) ou um dia (aaaa-mm-dd)
</div>
</form>
</div>
{% endblock %}
Loading…
Cancel
Save