From 131b98d4ccd44f95c7fa6f5dd55d1a61da02c9c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 23 May 2013 13:29:29 -0300 Subject: [PATCH] =?UTF-8?q?Sele=C3=A7=C3=A3o=20de=20conv=C3=AAnios=20por?= =?UTF-8?q?=20per=C3=ADodo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/convenios/admin.py | 22 ++++++++++++++++++- .../templates/convenios/change_list.html | 19 +++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/sigi/apps/convenios/admin.py b/sigi/apps/convenios/admin.py index 011ccf2..b66d7ce 100644 --- a/sigi/apps/convenios/admin.py +++ b/sigi/apps/convenios/admin.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from django.contrib import admin +from django.contrib.admin.views.main import ChangeList from sigi.apps.convenios.models import Projeto, Convenio, EquipamentoPrevisto, Anexo, Tramitacao, UnidadeAdministrativa from sigi.apps.casas.models import CasaLegislativa from sigi.apps.servicos.models import Servico @@ -68,6 +69,26 @@ class ConvenioAdmin(admin.ModelAdmin): get_uf.admin_order_field = 'casa_legislativa__municipio__uf__sigla' def changelist_view(self, request, extra_context=None): + import re + request.GET._mutable=True + if 'data_retorno_assinatura__gte' in request.GET: + value = request.GET.get('data_retorno_assinatura__gte','') + if value == '': + del request.GET['data_retorno_assinatura__gte'] + elif re.match('^\d*$', value): # Year only + request.GET['data_retorno_assinatura__gte'] = "%s-01-01" % value #Complete with january 1st + elif re.match('^\d*\D\d*$', value): # Year and month + request.GET['data_retorno_assinatura__gte'] = '%s-01' % value #Complete with 1st day of month + if 'data_retorno_assinatura__lte' in request.GET: + value = request.GET.get('data_retorno_assinatura__lte','') + if value == '': + del request.GET['data_retorno_assinatura__lte'] + elif re.match('^\d*$', value): # Year only + request.GET['data_retorno_assinatura__lte'] = "%s-01-01" % value #Complete with january 1st + elif re.match('^\d*\D\d*$', value): # Year and month + request.GET['data_retorno_assinatura__lte'] = '%s-01' % value #Complete with 1st day of month + request.GET._mutable=False + return super(ConvenioAdmin, self).changelist_view( request, extra_context={'query_str': '?' + request.META['QUERY_STRING']} @@ -103,7 +124,6 @@ class ConvenioAdmin(admin.ModelAdmin): def lookup_allowed(self, lookup, value): return super(ConvenioAdmin, self).lookup_allowed(lookup, value) or \ lookup in ['casa_legislativa__municipio__uf__codigo_ibge__exact'] - class EquipamentoPrevistoAdmin(admin.ModelAdmin): list_display = ('convenio', 'equipamento', 'quantidade') diff --git a/sigi/apps/convenios/templates/convenios/change_list.html b/sigi/apps/convenios/templates/convenios/change_list.html index eea3b0c..a3ea917 100644 --- a/sigi/apps/convenios/templates/convenios/change_list.html +++ b/sigi/apps/convenios/templates/convenios/change_list.html @@ -1,5 +1,5 @@ {% extends "admin/change_list.html" %} -{% load i18n reporting_tags %} +{% load i18n reporting_tags admin_list %} {% block extrastyle %} {{ block.super }} @@ -21,3 +21,20 @@ {% endif %} {% endblock %} + +{% block search %} +
+ +
+{% endblock %}