Browse Source

adição da opção de exportar contatos intelegis no formato CSV

stable/1.0
Breno Teixeira 12 years ago
parent
commit
37c1761013
  1. 20
      sigi/apps/casas/templates/casas/carrinho.html
  2. 17
      sigi/apps/casas/views.py

20
sigi/apps/casas/templates/casas/carrinho.html

@ -188,6 +188,26 @@
</li> </li>
</ul> </ul>
</fieldset> </fieldset>
<fieldset><legend>Contato Interlegis</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="Nome contato" class="action-select" checked="checked" />
<label>Nome</label>
</li>
<li><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected"
value="Cargo contato" class="action-select" checked="checked" />
<label>Cargo</label>
</li>
<li><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
<input type="checkbox" name="itens_csv_selected"
value="Email contato" class="action-select" checked="checked" />
<label>Email</label>
</li>
</ul>
</fieldset>
<ul class="botoes"> <ul class="botoes">
<li><input type="submit" value="Exportar CSV" /></li> <li><input type="submit" value="Exportar CSV" /></li>
</ul> </ul>

17
sigi/apps/casas/views.py

@ -3,7 +3,7 @@ from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from geraldo.generators import PDFGenerator from geraldo.generators import PDFGenerator
from sigi.apps.casas.models import CasaLegislativa from sigi.apps.casas.models import CasaLegislativa, Funcionario
from sigi.apps.casas.reports import CasasLegislativasLabels from sigi.apps.casas.reports import CasasLegislativasLabels
from sigi.apps.casas.reports import CasasLegislativasLabelsSemPresidente from sigi.apps.casas.reports import CasasLegislativasLabelsSemPresidente
from sigi.apps.casas.reports import CasasLegislativasReport from sigi.apps.casas.reports import CasasLegislativasReport
@ -302,7 +302,8 @@ def export_csv(request):
response = HttpResponse(mimetype='text/csv') response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=casas.csv' response['Content-Disposition'] = 'attachment; filename=casas.csv'
csv_writer = csv.writer(response) writer = csv.writer(response)
casas = carrinhoOrGet_for_qs(request) casas = carrinhoOrGet_for_qs(request)
if not casas or not request.POST: if not casas or not request.POST:
return HttpResponseRedirect('../') return HttpResponseRedirect('../')
@ -311,11 +312,11 @@ def export_csv(request):
atributos2 = [s.encode("utf-8") for s in atributos] atributos2 = [s.encode("utf-8") for s in atributos]
try: try:
atributos2.insert(atributos2.index(u'Município'), u'UF') atributos2.insert(atributos2.index('Município'), u'UF')
except ValueError: except ValueError:
pass pass
csv_writer.writerow(atributos2) writer.writerow(atributos2)
for casa in casas: for casa in casas:
lista = [] lista = []
@ -352,9 +353,15 @@ def export_csv(request):
lista.append(casa.total_parlamentares) lista.append(casa.total_parlamentares)
elif u"Última alteração de endereco" == atributo: elif u"Última alteração de endereco" == atributo:
lista.append(casa.ult_alt_endereco) lista.append(casa.ult_alt_endereco)
elif u"Nome contato" == atributo:
lista.append(casa.funcionario_set.filter(setor="contato_interlegis")[0].nome.encode("utf-8"))
elif u"Cargo contato" == atributo:
lista.append(casa.funcionario_set.filter(setor="contato_interlegis")[0].cargo.encode("utf-8"))
elif u"Email contato" == atributo:
lista.append(casa.funcionario_set.filter(setor="contato_interlegis")[0].email.encode("utf-8"))
else: else:
pass pass
csv_writer.writerow(lista) writer.writerow(lista)
return response return response

Loading…
Cancel
Save