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. 32
      sigi/apps/convenios/templates/convenios/carrinho.html
  3. 23
      sigi/apps/convenios/views.py

30
sigi/apps/convenios/admin.py

@ -110,28 +110,16 @@ class ConvenioAdmin(BaseModelAdmin):
link_sigad.allow_tags = True
def changelist_view(self, request, extra_context=None):
def normaliza_data(nome_param):
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
from sigi.apps.convenios.views import normaliza_data
request.GET._mutable = True
normaliza_data('data_retorno_assinatura__gte')
normaliza_data('data_retorno_assinatura__lte')
normaliza_data('data_sigad__gte')
normaliza_data('data_sigad__lte')
normaliza_data('data_sigi__gte')
normaliza_data('data_sigi__lte')
normaliza_data('data_solicitacao__gte')
normaliza_data('data_solicitacao__lte')
normaliza_data(request.GET, 'data_retorno_assinatura__gte')
normaliza_data(request.GET, 'data_retorno_assinatura__lte')
normaliza_data(request.GET, 'data_sigad__gte')
normaliza_data(request.GET, 'data_sigad__lte')
normaliza_data(request.GET, 'data_sigi__gte')
normaliza_data(request.GET, 'data_sigi__lte')
normaliza_data(request.GET, 'data_solicitacao__gte')
normaliza_data(request.GET, 'data_solicitacao__lte')
request.GET._mutable = False
return super(ConvenioAdmin, self).changelist_view(

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

@ -21,8 +21,8 @@
{% block action %}deleta_itens_carrinho{% endblock %}
{% block tabela %}
<table>
<thead>
<table class="table table-striped">
<thead class="thead-dark">
<tr>
{%if not carIsEmpty%}
<th class="sorted ascending"><!-- <input type="checkbox" id="action-toggle" style="display: inline;">-->
@ -38,7 +38,7 @@
</thead>
<tbody>
{% for convenio in paginas.object_list %}
<tr class="{% cycle 'row1' 'row2' %}">
<tr>
{%if not carIsEmpty%}
<th><input type="checkbox" name="_selected_action"
value="{{convenio.id|safe}}" class="action-select" /></th>
@ -56,13 +56,12 @@
{% endblock %}
{% block botoes %}
<div id="tabs">
<ul>
<li><a href="#tabs-1">{% trans 'Relatório' %}</a></li>
<li><a href="#tabs-2">{% trans 'Arquivo CSV (Excel, Calc)' %}</a></li>
</ul>
<div id="tabs-1">
<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>
<li role="presentation"><a href="#tabs-2" aria-controls="tabs-2" role="tab" data-toggle="tab">{% trans 'Arquivo CSV (Excel, Calc)' %}</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="tabs-1">
<form action="../reports/{{ query_str }}" method="post">{% csrf_token %}
<fieldset>
<legend>{% trans 'Relatório por' %}</legend>
@ -94,14 +93,13 @@
</li>
</ul>
</fieldset>
<ul class="botoes">
<li><input type="submit" value="Gerar Relatório"></li>
</ul>
<input type="submit" value="Gerar Relatório" type="button" class="btn btn-primary">
</form>
</div>
<div id="tabs-2">
<div role="tabpanel" class="tab-pane" id="tabs-2">
<form action="../csv/{{query_str}}" method="post">{% csrf_token %}
<fieldset><legend>{% trans 'Escolha os atributos para exportar' %}</legend>
<fieldset>
<legend>{% trans 'Escolha os atributos para exportar' %}</legend>
<ul id="sortable" class="tabs-conteudo">
<li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
@ -153,9 +151,7 @@
</li>
</ul>
</fieldset>
<ul class="botoes">
<li><input type="submit" value="Exportar CSV" /></li>
</ul>
<input type="submit" value="Exportar CSV" type="button" class="btn btn-primary"/>
</form>
</div>
</div>

23
sigi/apps/convenios/views.py

@ -36,10 +36,32 @@ def query_ordena(qs, o, ot):
qs = qs.order_by("-" + aux)
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):
kwargs = {}
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():
if k not in ['page', 'pop', 'q', '_popup']:
if not k == 'o':
@ -51,7 +73,6 @@ def get_for_qs(get, qs):
ids = 1
break
qs = qs.filter(**kwargs)
if ids:
query = 'id IN (' + kwargs['ids'].__str__() + ')'
qs = Convenio.objects.extra(where=[query])

Loading…
Cancel
Save