Browse Source

Bug na exportação de convenios

pull/66/head
Sesostris Vieira 4 years ago
parent
commit
0b63d7c4ec
  1. 30
      sigi/apps/convenios/admin.py
  2. 170
      sigi/apps/convenios/templates/convenios/carrinho.html
  3. 25
      sigi/apps/convenios/views.py

30
sigi/apps/convenios/admin.py

@ -110,28 +110,16 @@ class ConvenioAdmin(BaseModelAdmin):
link_sigad.allow_tags = True link_sigad.allow_tags = True
def changelist_view(self, request, extra_context=None): def changelist_view(self, request, extra_context=None):
def normaliza_data(nome_param): from sigi.apps.convenios.views import normaliza_data
import re
if nome_param in request.GET:
value = request.GET.get(nome_param, '')
if value == '':
del request.GET[nome_param]
elif re.match('^\d*$', value): # Year only
# Complete with january 1st
request.GET[nome_param] = "%s-01-01" % value
elif re.match('^\d*\D\d*$', value): # Year and month
# Complete with 1st day of month
request.GET[nome_param] = '%s-01' % value
request.GET._mutable = True request.GET._mutable = True
normaliza_data('data_retorno_assinatura__gte') normaliza_data(request.GET, 'data_retorno_assinatura__gte')
normaliza_data('data_retorno_assinatura__lte') normaliza_data(request.GET, 'data_retorno_assinatura__lte')
normaliza_data('data_sigad__gte') normaliza_data(request.GET, 'data_sigad__gte')
normaliza_data('data_sigad__lte') normaliza_data(request.GET, 'data_sigad__lte')
normaliza_data('data_sigi__gte') normaliza_data(request.GET, 'data_sigi__gte')
normaliza_data('data_sigi__lte') normaliza_data(request.GET, 'data_sigi__lte')
normaliza_data('data_solicitacao__gte') normaliza_data(request.GET, 'data_solicitacao__gte')
normaliza_data('data_solicitacao__lte') normaliza_data(request.GET, 'data_solicitacao__lte')
request.GET._mutable = False request.GET._mutable = False
return super(ConvenioAdmin, self).changelist_view( return super(ConvenioAdmin, self).changelist_view(

170
sigi/apps/convenios/templates/convenios/carrinho.html

@ -21,8 +21,8 @@
{% block action %}deleta_itens_carrinho{% endblock %} {% block action %}deleta_itens_carrinho{% endblock %}
{% block tabela %} {% block tabela %}
<table> <table class="table table-striped">
<thead> <thead class="thead-dark">
<tr> <tr>
{%if not carIsEmpty%} {%if not carIsEmpty%}
<th class="sorted ascending"><!-- <input type="checkbox" id="action-toggle" style="display: inline;">--> <th class="sorted ascending"><!-- <input type="checkbox" id="action-toggle" style="display: inline;">-->
@ -38,7 +38,7 @@
</thead> </thead>
<tbody> <tbody>
{% for convenio in paginas.object_list %} {% for convenio in paginas.object_list %}
<tr class="{% cycle 'row1' 'row2' %}"> <tr>
{%if not carIsEmpty%} {%if not carIsEmpty%}
<th><input type="checkbox" name="_selected_action" <th><input type="checkbox" name="_selected_action"
value="{{convenio.id|safe}}" class="action-select" /></th> value="{{convenio.id|safe}}" class="action-select" /></th>
@ -56,107 +56,103 @@
{% endblock %} {% endblock %}
{% block botoes %} {% block botoes %}
<div id="tabs"> <ul class="nav nav-tabs" role="tablist">
<li class="active" role="presentation"><a href="#tabs-1" aria-controls="tabs-1" role="tab" data-toggle="tab">{% trans 'Relatório' %}</a></li>
<ul> <li role="presentation"><a href="#tabs-2" aria-controls="tabs-2" role="tab" data-toggle="tab">{% trans 'Arquivo CSV (Excel, Calc)' %}</a></li>
<li><a href="#tabs-1">{% trans 'Relatório' %}</a></li> </ul>
<li><a href="#tabs-2">{% trans 'Arquivo CSV (Excel, Calc)' %}</a></li> <div class="tab-content">
</ul> <div role="tabpanel" class="tab-pane active" id="tabs-1">
<div id="tabs-1"> <form action="../reports/{{ query_str }}" method="post">{% csrf_token %}
<form action="../reports/{{ query_str }}" method="post">{% csrf_token %} <fieldset>
<fieldset> <legend>{% trans 'Relatório por' %}</legend>
<legend>{% trans 'Relatório por' %}</legend> <ul class="tabs-conteudo">
<ul class="tabs-conteudo"> <li>
<li> <input type="radio" name="filtro_casa" value="tudo" checked="checked"/>
<input type="radio" name="filtro_casa" value="tudo" checked="checked"/> <label>{% trans 'Todos' %}</label>
<label>{% trans 'Todos' %}</label> </li>
</li> <li>
<li> <input type="radio" name="filtro_casa" value="cm"/>
<input type="radio" name="filtro_casa" value="cm"/> <label>{% trans 'Câmara Municipal' %}</label>
<label>{% trans 'Câmara Municipal' %}</label> </li>
</li> <li>
<li> <input type="radio" name="filtro_casa" value="al" />
<input type="radio" name="filtro_casa" value="al" /> <label>{% trans 'Assembléia Legislativa' %}</label>
<label>{% trans 'Assembléia Legislativa' %}</label> </li>
</li> </ul>
</ul>
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend>{% trans 'Com data de aceite? (Equipada)' %}</legend> <legend>{% trans 'Com data de aceite? (Equipada)' %}</legend>
<ul class="tabs-conteudo"> <ul class="tabs-conteudo">
<li> <li>
<input type="radio" name="data_aceite" value="sim" checked="checked" /> <input type="radio" name="data_aceite" value="sim" checked="checked" />
<label>{% trans 'Sim' %}</label> <label>{% trans 'Sim' %}</label>
</li> </li>
<li> <li>
<input type="radio" name="data_aceite" value="nao" /> <input type="radio" name="data_aceite" value="nao" />
<label>{% trans 'Não' %}</label> <label>{% trans 'Não' %}</label>
</li> </li>
</ul> </ul>
</fieldset> </fieldset>
<ul class="botoes"> <input type="submit" value="Gerar Relatório" type="button" class="btn btn-primary">
<li><input type="submit" value="Gerar Relatório"></li> </form>
</ul>
</form>
</div> </div>
<div id="tabs-2"> <div role="tabpanel" class="tab-pane" id="tabs-2">
<form action="../csv/{{query_str}}" method="post">{% csrf_token %} <form action="../csv/{{query_str}}" method="post">{% csrf_token %}
<fieldset><legend>{% trans 'Escolha os atributos para exportar' %}</legend> <fieldset>
<ul id="sortable" class="tabs-conteudo"> <legend>{% trans 'Escolha os atributos para exportar' %}</legend>
<li> <ul id="sortable" class="tabs-conteudo">
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <li>
<input type="checkbox" name="itens_csv_selected" value="No. Processo" <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="No. Processo"
class="action-select" checked="checked" /> class="action-select" checked="checked" />
<label>{% trans 'Nº Processo' %}</label> <label>{% trans 'Nº Processo' %}</label>
</li> </li>
<li> <li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="No. Convênio" <input type="checkbox" name="itens_csv_selected" value="No. Convênio"
class="action-select" checked="checked" /> class="action-select" checked="checked" />
<label>{% trans 'Nº Convênio' %}</label> <label>{% trans 'Nº Convênio' %}</label>
</li> </li>
<li> <li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Projeto" <input type="checkbox" name="itens_csv_selected" value="Projeto"
class="action-select" checked="checked" /> class="action-select" checked="checked" />
<label>{% trans 'Projeto' %}</label> <label>{% trans 'Projeto' %}</label>
</li> </li>
<li> <li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Casa Legislativa" <input type="checkbox" name="itens_csv_selected" value="Casa Legislativa"
class="action-select" checked="checked" /> class="action-select" checked="checked" />
<label>{% trans 'Casa Legislativa' %}</label> <label>{% trans 'Casa Legislativa' %}</label>
</li> </li>
<li> <li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Data de Adesão" <input type="checkbox" name="itens_csv_selected" value="Data de Adesão"
class="action-select" checked="checked" /> class="action-select" checked="checked" />
<label>{% trans 'Data de Adesão' %}</label> <label>{% trans 'Data de Adesão' %}</label>
</li> </li>
<li> <li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Data de Convênio" <input type="checkbox" name="itens_csv_selected" value="Data de Convênio"
class="action-select" checked="checked" /> class="action-select" checked="checked" />
<label>{% trans 'Data de Convênio' %}</label> <label>{% trans 'Data de Convênio' %}</label>
</li> </li>
<li> <li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Data da Publicacao no D.O." <input type="checkbox" name="itens_csv_selected" value="Data da Publicacao no D.O."
class="action-select" checked="checked" /> class="action-select" checked="checked" />
<label>{% trans 'Data da Publicação no Diário Oficial' %}</label> <label>{% trans 'Data da Publicação no Diário Oficial' %}</label>
</li> </li>
<li> <li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Data Equipada" <input type="checkbox" name="itens_csv_selected" value="Data Equipada"
class="action-select" checked="checked" /> class="action-select" checked="checked" />
<label>{% trans 'Data Equipada' %}</label> <label>{% trans 'Data Equipada' %}</label>
</li> </li>
</ul> </ul>
</fieldset> </fieldset>
<ul class="botoes"> <input type="submit" value="Exportar CSV" type="button" class="btn btn-primary"/>
<li><input type="submit" value="Exportar CSV" /></li> </form>
</ul> </div>
</form>
</div>
</div> </div>
{% endblock %} {% endblock %}

25
sigi/apps/convenios/views.py

@ -36,10 +36,32 @@ def query_ordena(qs, o, ot):
qs = qs.order_by("-" + aux) qs = qs.order_by("-" + aux)
return qs return qs
def normaliza_data(get, nome_param):
import re
if nome_param in get:
value = get.get(nome_param, '')
if value == '':
del get[nome_param]
elif re.match('^\d*$', value): # Year only
# Complete with january 1st
get[nome_param] = "%s-01-01" % value
elif re.match('^\d*\D\d*$', value): # Year and month
# Complete with 1st day of month
get[nome_param] = '%s-01' % value
def get_for_qs(get, qs): def get_for_qs(get, qs):
kwargs = {} kwargs = {}
ids = 0 ids = 0
get._mutable = True
normaliza_data(get, 'data_retorno_assinatura__gte')
normaliza_data(get, 'data_retorno_assinatura__lte')
normaliza_data(get, 'data_sigad__gte')
normaliza_data(get, 'data_sigad__lte')
normaliza_data(get, 'data_sigi__gte')
normaliza_data(get, 'data_sigi__lte')
normaliza_data(get, 'data_solicitacao__gte')
normaliza_data(get, 'data_solicitacao__lte')
get._mutable = False
for k, v in get.iteritems(): for k, v in get.iteritems():
if k not in ['page', 'pop', 'q', '_popup']: if k not in ['page', 'pop', 'q', '_popup']:
if not k == 'o': if not k == 'o':
@ -50,8 +72,7 @@ def get_for_qs(get, qs):
if(str(k) == 'ids'): if(str(k) == 'ids'):
ids = 1 ids = 1
break break
qs = qs.filter(**kwargs) qs = qs.filter(**kwargs)
if ids: if ids:
query = 'id IN (' + kwargs['ids'].__str__() + ')' query = 'id IN (' + kwargs['ids'].__str__() + ')'
qs = Convenio.objects.extra(where=[query]) qs = Convenio.objects.extra(where=[query])

Loading…
Cancel
Save