From f8059698a4504670a61438441f18846ce1c77ed2 Mon Sep 17 00:00:00 2001 From: Sesostris Vieira Date: Mon, 11 Apr 2016 19:30:19 -0300 Subject: [PATCH] Adiciona download csv de casas no painel do gerente --- .../casas/lista_casas_carteira_snippet.html | 10 +++++-- sigi/apps/casas/views.py | 29 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/sigi/apps/casas/templates/casas/lista_casas_carteira_snippet.html b/sigi/apps/casas/templates/casas/lista_casas_carteira_snippet.html index 8604b91..bcd53a4 100644 --- a/sigi/apps/casas/templates/casas/lista_casas_carteira_snippet.html +++ b/sigi/apps/casas/templates/casas/lista_casas_carteira_snippet.html @@ -2,7 +2,11 @@ {% load smart_pagination %}
-

{% trans "Suas casas" %}

+
+

{% trans "Suas casas" %} + +

+
@@ -75,7 +79,9 @@ {% endfor %}
-

{% blocktrans with count=page_obj.paginator.count %}{{ count }} casas encontradas.{% endblocktrans %}

+

{% blocktrans with count=page_obj.paginator.count %}{{ count }} casas encontradas.{% endblocktrans %} + +

{% 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 %} diff --git a/sigi/apps/casas/views.py b/sigi/apps/casas/views.py index b34cb7b..d8cea61 100644 --- a/sigi/apps/casas/views.py +++ b/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) \ No newline at end of file