Browse Source

Adiciona download csv de casas no painel do gerente

whois_api
Sesostris Vieira 9 years ago
parent
commit
f8059698a4
  1. 10
      sigi/apps/casas/templates/casas/lista_casas_carteira_snippet.html
  2. 29
      sigi/apps/casas/views.py

10
sigi/apps/casas/templates/casas/lista_casas_carteira_snippet.html

@ -2,7 +2,11 @@
{% load smart_pagination %}
<div class="panel panel-primary flex-col">
<div class="panel-heading"><h3 class="panel-title">{% trans "Suas casas" %}</h3></div>
<div class="panel-heading">
<h3 class="panel-title">{% trans "Suas casas" %}
<a href="?{{ qs_servidor }}&{{ qs_servico }}&{{ qs_regiao }}&snippet=lista&f=csv" title="{% trans "Download" %}" aria-label="{% trans "Download" %}"><span class="glyphicon glyphicon-download" aria-hidden="true"</span></a>
</h3>
</div>
<div class="panel-body">
<div id="filter-panel">
<form name="servico-form" action="" method="get">
@ -75,7 +79,9 @@
{% endfor %}
</table>
</div>
<p>{% blocktrans with count=page_obj.paginator.count %}{{ count }} casas encontradas.{% endblocktrans %}</p>
<p>{% blocktrans with count=page_obj.paginator.count %}{{ count }} casas encontradas.{% endblocktrans %}
<a href="?{{ qs_servidor }}&{{ qs_servico }}&{{ qs_regiao }}&snippet=lista&f=csv" title="{% trans "Download" %}" aria-label="{% trans "Download" %}"><span class="glyphicon glyphicon-download" aria-hidden="true"</span></a>
</p>
{% if page_obj.paginator.num_pages > 1 %}
{% smart_paginator page_obj=page_obj querystring=qs_servidor|add:'&'|add:qs_servico|add:'&'|add:qs_regiao %}
{% endif %}

29
sigi/apps/casas/views.py

@ -18,6 +18,7 @@ from sigi.apps.servicos.models import TipoServico
from sigi.apps.servidores.models import Servidor
from sigi.apps.ocorrencias.models import Ocorrencia
from django.db.models import Count, Q
from django.http.response import JsonResponse
# @param qs: queryset
@ -607,6 +608,7 @@ def painel_relacionamento(request):
snippet = request.GET.get('snippet', '')
seletor = request.GET.get('s', None)
servidor = request.GET.get('servidor', None)
format = request.GET.get('f', 'html')
if servidor is None:
gerente = request.user.servidor
@ -648,7 +650,32 @@ def painel_relacionamento(request):
context['page_obj'] = pagina
if snippet == 'lista':
if format == 'csv':
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=casas.csv'
writer = csv.writer(response)
writer.writerow([
_(u"Casa legislativa").encode('utf8'),
_(u"Região").encode('utf8'),
_(u"Estado").encode('utf8'),
_(u"Mesorregião").encode('utf8'),
_(u"Microrregião").encode('utf8'),
_(u"Gerente de relacionamento").encode('utf8'),
_(u"Serviços").encode('utf8'),
])
for c in casas:
writer.writerow([
c.nome.encode('utf8'),
c.municipio.uf.get_regiao_display().encode('utf8'),
c.municipio.uf.sigla.encode('utf8'),
c.municipio.microrregiao.mesorregiao.nome.encode('utf8'),
c.municipio.microrregiao.nome.encode('utf8'),
c.gerente_contas.nome_completo.encode('utf8'),
(u", ".join([s.tipo_servico.nome for s in c.servico_set.filter(data_desativacao__isnull=True)])).encode('utf8'),
])
return response
return render(request, 'casas/lista_casas_carteira_snippet.html', context)
if snippet == 'resumo':
return render(request, 'casas/resumo_carteira_snippet.html', context)
return render(request, 'casas/resumo_carteira_snippet.html', context)
return render(request, 'casas/painel.html', context)
Loading…
Cancel
Save