From d1c4935b278f978d20574095714c9595b8a9c6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 23 May 2013 19:24:02 -0300 Subject: [PATCH] =?UTF-8?q?Adicionado=20filtro=20por=20data=20de=20visita?= =?UTF-8?q?=20na=20changelist=20de=20diagn=C3=B3sticos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/diagnosticos/admin.py | 23 +++++++++++++++++++ .../diagnosticos/diagnostico/change_list.html | 19 +++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 sigi/templates/admin/diagnosticos/diagnostico/change_list.html diff --git a/sigi/apps/diagnosticos/admin.py b/sigi/apps/diagnosticos/admin.py index 8e9e8fb..034f3a1 100644 --- a/sigi/apps/diagnosticos/admin.py +++ b/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') diff --git a/sigi/templates/admin/diagnosticos/diagnostico/change_list.html b/sigi/templates/admin/diagnosticos/diagnostico/change_list.html new file mode 100644 index 0000000..e2ca667 --- /dev/null +++ b/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 %} +
+ +
+{% endblock %}