Browse Source

Seleção de convênios por período

stable/1.0
Sesostris Vieira 12 years ago
parent
commit
131b98d4cc
  1. 22
      sigi/apps/convenios/admin.py
  2. 19
      sigi/apps/convenios/templates/convenios/change_list.html

22
sigi/apps/convenios/admin.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.contrib import admin 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.convenios.models import Projeto, Convenio, EquipamentoPrevisto, Anexo, Tramitacao, UnidadeAdministrativa
from sigi.apps.casas.models import CasaLegislativa from sigi.apps.casas.models import CasaLegislativa
from sigi.apps.servicos.models import Servico 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' get_uf.admin_order_field = 'casa_legislativa__municipio__uf__sigla'
def changelist_view(self, request, extra_context=None): 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( return super(ConvenioAdmin, self).changelist_view(
request, request,
extra_context={'query_str': '?' + request.META['QUERY_STRING']} extra_context={'query_str': '?' + request.META['QUERY_STRING']}
@ -104,7 +125,6 @@ class ConvenioAdmin(admin.ModelAdmin):
return super(ConvenioAdmin, self).lookup_allowed(lookup, value) or \ return super(ConvenioAdmin, self).lookup_allowed(lookup, value) or \
lookup in ['casa_legislativa__municipio__uf__codigo_ibge__exact'] lookup in ['casa_legislativa__municipio__uf__codigo_ibge__exact']
class EquipamentoPrevistoAdmin(admin.ModelAdmin): class EquipamentoPrevistoAdmin(admin.ModelAdmin):
list_display = ('convenio', 'equipamento', 'quantidade') list_display = ('convenio', 'equipamento', 'quantidade')
list_display_links = ('convenio', 'equipamento') list_display_links = ('convenio', 'equipamento')

19
sigi/apps/convenios/templates/convenios/change_list.html

@ -1,5 +1,5 @@
{% extends "admin/change_list.html" %} {% extends "admin/change_list.html" %}
{% load i18n reporting_tags %} {% load i18n reporting_tags admin_list %}
{% block extrastyle %} {% block extrastyle %}
{{ block.super }} {{ block.super }}
@ -21,3 +21,20 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% 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_retorno_assinatura__gte">Conveniadas a partir de:</label>
<input type="text" size="10" name="data_retorno_assinatura__gte" value="" id="data_retorno_assinatura__gte" class="vDateField"/>
<label for="data_retorno_assinatura__lte">até:</label>
<input type="text" size="10" name="data_retorno_assinatura__lte" value="" id="data_retorno_assinatura__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