Browse Source

Adicionando exportacao csv em convenio

diagnosticos
Starlone (Estagiario) 14 years ago
parent
commit
520b16df24
  1. 64
      sigi/apps/convenios/templates/convenios/carrinho.html
  2. 42
      sigi/apps/convenios/views.py
  3. 5
      sigi/urls.py

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

@ -59,7 +59,8 @@
<div id="tabs">
<ul>
<li><a href="#tabs-1">Relatório</a></li>
<li><a href="#tabs-1">Relatório</a></li>
<li><a href="#tabs-2">Arquivo CSV (Excel, Calc)</a></li>
</ul>
<div id="tabs-1">
<form action="../reports/{{ query_str }}" method="post">
@ -93,6 +94,65 @@
<li><input type="submit" value="Gerar Relatório"></li>
</ul>
</form>
</div>
</div>
<div id="tabs-2">
<form action="../csv/{{query_str}}" method="post">
<fieldset><legend>Escolha os atributos para exportar</legend>
<ul id="sortable" class="tabs-conteudo">
<li>
<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" />
<label>Nº Processo</label>
</li>
<li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="No. Convênio"
class="action-select" checked="checked" />
<label>Nº Convênio</label>
</li>
<li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Projeto"
class="action-select" checked="checked" />
<label>Projeto</label>
</li>
<li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Casa Legislativa"
class="action-select" checked="checked" />
<label>Casa Legislativa</label>
</li>
<li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Data de Adesão"
class="action-select" checked="checked" />
<label>Data de Adesão</label>
</li>
<li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Data de Convênio"
class="action-select" checked="checked" />
<label>Data de Convênio</label>
</li>
<li>
<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."
class="action-select" checked="checked" />
<label>Data da Publicação no Diário Oficial</label>
</li>
<li>
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected" value="Data Equipada"
class="action-select" checked="checked" />
<label>Data Equipada</label>
</li>
</ul>
</fieldset>
<ul class="botoes">
<li><input type="submit" value="Exportar CSV" /></li>
</ul>
</form>
</div>
</div>
{% endblock %}

42
sigi/apps/convenios/views.py

@ -20,6 +20,8 @@ from django.conf import settings
import datetime
import csv
def query_ordena(qs,o,ot):
list_display = ('num_convenio', 'casa_legislativa',
'data_adesao','data_retorno_assinatura','data_termo_aceite',
@ -292,4 +294,44 @@ def report_regiao(request,regiao='NE'):
pisa.startViewer(response)
return response
def export_csv(request):
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=convenios.csv'
csv_writer = csv.writer(response)
convenios = carrinhoOrGet_for_qs(request)
if not convenios:
return HttpResponseRedirect('../')
if request.POST:
atributos = request.POST.getlist("itens_csv_selected")
atributos2 = [s.encode("utf-8") for s in atributos]
csv_writer.writerow(atributos2)
for convenio in convenios:
lista = []
for atributo in atributos:
if u"No. Processo" == atributo:
lista.append(convenio.num_processo_sf.encode("utf-8"))
elif u"No. Convênio" == atributo:
lista.append(convenio.num_convenio.encode("utf-8"))
elif u"Projeto" == atributo:
lista.append(convenio.projeto.nome.encode("utf-8"))
elif u"Casa Legislativa" == atributo:
lista.append(convenio.casa_legislativa.nome.encode("utf-8"))
elif u"Data de Adesão" == atributo:
lista.append(convenio.data_adesao.strftime("%d/%m/%Y").encode("utf-8"))
elif u"Data de Convênio" == atributo:
lista.append(convenio.data_retorno_assinatura.strftime("%d/%m/%Y").encode("utf-8"))
elif u"Data da Publicacao no D.O." == atributo:
lista.append(convenio.data_pub_diario.strftime("%d/%m/%Y").encode("utf-8"))
elif u"Data Equipada" == atributo:
lista.append(convenio.data_termo_aceite.strftime("%d/%m/%Y").encode("utf-8"))
else:
pass
csv_writer.writerow(lista)
return response

5
sigi/urls.py

@ -48,7 +48,10 @@ urlpatterns = patterns(
'sigi.apps.convenios.views.visualizar_carrinho'),
#CSV Casa
(r'^casas/casalegislativa/csv/',
'sigi.apps.casas.views.export_csv'),
'sigi.apps.casas.views.export_csv'),
#CSV Convenio
(r'^convenios/convenio/csv/',
'sigi.apps.convenios.views.export_csv'),
# Resumo por região PDF
(r'^reportsRegiao/(?P<regiao>\w+)',
'sigi.apps.convenios.views.report_regiao'),

Loading…
Cancel
Save