Browse Source

Adicionado filtro por data de visita na changelist de diagnósticos

stable/1.0
Sesostris Vieira 12 years ago
parent
commit
d1c4935b27
  1. 23
      sigi/apps/diagnosticos/admin.py
  2. 19
      sigi/templates/admin/diagnosticos/diagnostico/change_list.html

23
sigi/apps/diagnosticos/admin.py

@ -80,6 +80,29 @@ class DiagnosticoAdmin(BaseEntityAdmin):
return super(DiagnosticoAdmin, 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_visita_inicio__gte' in request.GET:
value = request.GET.get('data_visita_inicio__gte','')
if value == '':
del request.GET['data_visita_inicio__gte']
elif re.match('^\d*$', value): # Year only
request.GET['data_visita_inicio__gte'] = "%s-01-01" % value #Complete with january 1st
elif re.match('^\d*\D\d*$', value): # Year and month
request.GET['data_visita_inicio__gte'] = '%s-01' % value #Complete with 1st day of month
if 'data_visita_inicio__lte' in request.GET:
value = request.GET.get('data_visita_inicio__lte','')
if value == '':
del request.GET['data_visita_inicio__lte']
elif re.match('^\d*$', value): # Year only
request.GET['data_visita_inicio__lte'] = "%s-01-01" % value #Complete with january 1st
elif re.match('^\d*\D\d*$', value): # Year and month
request.GET['data_visita_inicio__lte'] = '%s-01' % value #Complete with 1st day of month
request.GET._mutable=False
return super(DiagnosticoAdmin, self).changelist_view(request, extra_context)
class EscolhaAdmin(admin.ModelAdmin):
search_fields = ('title',)
list_display = ('title', 'schema', 'schema_to_open')

19
sigi/templates/admin/diagnosticos/diagnostico/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_visita_inicio__gte">Visitados a partir de:</label>
<input type="text" size="10" name="data_visita_inicio__gte" value="" id="data_visita_inicio__gte" class="vDateField"/>
<label for="data_visita_inicio__lte">até:</label>
<input type="text" size="10" name="data_visita_inicio__lte" value="" id="data_visita_inicio__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