Browse Source

Adicionando exportação para arquivo csv

diagnosticos
Camilo Carlos (Estagiario) 15 years ago
parent
commit
f7475be5f6
  1. 1
      sigi/apps/casas/templates/casas/change_list.html
  2. 16
      sigi/apps/casas/views.py
  3. 2
      sigi/urls.py

1
sigi/apps/casas/templates/casas/change_list.html

@ -5,6 +5,7 @@
{% if has_add_permission %}
<ul class="object-tools">
<li><a href="reports/{{query_str}}">Relatório</a> </li>
<li><a href="csv/{{query_str}}">Exportar CSV</a> </li>
<li><a href="casas_sem_convenio_report/{{query_str}}">Casas sem convênio</a> </li>
<li><a href="labels/{{ query_str }}">Gerar etiquetas</a></li>
<li>

16
sigi/apps/casas/views.py

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
from django.http import HttpResponse, HttpResponseRedirect
from geraldo.generators import PDFGenerator
from sigi.apps.casas.models import CasaLegislativa
from sigi.apps.casas.reports import CasasLegislativasLabels
from sigi.apps.casas.reports import CasasLegislativasReport
from sigi.apps.casas.reports import CasasSemConvenioReport
import csv
def labels_report(request, id=None):
""" TODO: adicionar suporte para resultado de pesquisa do admin.
@ -58,3 +59,16 @@ def casas_sem_convenio_report(request):
report = CasasSemConvenioReport(queryset=qs)
report.generate_by(PDFGenerator, filename=response)
return response
def export_csv(request):
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=casas.csv'
csv_writer = csv.writer(response)
casas = CasaLegislativa.objects.filter(municipio__uf__sigla=u'MG')
for casa in casas:
csv_writer.writerow([casa.nome.encode("utf-8"), casa.municipio.uf.sigla.encode("utf-8")])
return response

2
sigi/urls.py

@ -16,6 +16,8 @@ urlpatterns = patterns(
# reports
(r'^casas/casalegislativa/reports/',
'sigi.apps.casas.views.report'),
(r'^casas/casalegislativa/csv/',
'sigi.apps.casas.views.export_csv'),
(r'^casas/casalegislativa/casas_sem_convenio_report/',
'sigi.apps.casas.views.casas_sem_convenio_report'),
(r'^convenios/convenio/reports_por_cm/',

Loading…
Cancel
Save