From 7d14171ee8b5b4f584a45bc4dd62d8fe4b4cea27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Mon, 17 May 2021 23:37:43 -0300 Subject: [PATCH] Lista de gerentes interlegis --- .../templates/casas/gerentes_interlegis.html | 57 +++++++ .../casas/gerentes_interlegis_pdf.html | 143 ++++++++++++++++++ sigi/apps/casas/urls.py | 2 + sigi/apps/casas/views.py | 62 ++++++++ sigi/apps/home/templatetags/menu_conf.yaml | 2 + 5 files changed, 266 insertions(+) create mode 100644 sigi/apps/casas/templates/casas/gerentes_interlegis.html create mode 100644 sigi/apps/casas/templates/casas/gerentes_interlegis_pdf.html diff --git a/sigi/apps/casas/templates/casas/gerentes_interlegis.html b/sigi/apps/casas/templates/casas/gerentes_interlegis.html new file mode 100644 index 0000000..289a8e0 --- /dev/null +++ b/sigi/apps/casas/templates/casas/gerentes_interlegis.html @@ -0,0 +1,57 @@ +{% extends "admin/base_site.html" %} +{% load i18n admin_static %} +{% load static from staticfiles %} + +{% block coltype %}colMS{% endblock %} + +{% block content_title %}

{% blocktrans %}Gerentes Interlegis{% endblocktrans %}

{% endblock %} + +{% block content %} + + +
+ {% for linha in gerentes %} +
+
+

{{ linha.gerente.nome_completo }} {{ linha.gerente.casas_que_gerencia.count }}

+
+
+ +
+ {% for uf in linha.ufs %} +
+
    + {% for casa in uf.2 %} +
  • + {{ casa }}
  • + {% endfor %} +
+
+ {% endfor %} +
+
+
+ {% endfor %} +
+{% endblock %} \ No newline at end of file diff --git a/sigi/apps/casas/templates/casas/gerentes_interlegis_pdf.html b/sigi/apps/casas/templates/casas/gerentes_interlegis_pdf.html new file mode 100644 index 0000000..c0dd300 --- /dev/null +++ b/sigi/apps/casas/templates/casas/gerentes_interlegis_pdf.html @@ -0,0 +1,143 @@ +{% load static from staticfiles %} +{% load i18n %} + + + + + Casa Legislativa + + + + + + + + + + + + + + {% for linha in gerentes %} + {% for uf in linha.ufs %} + + {% if forloop.first %} + + {% else %} + + {% endif %} + + + + {% endfor %} + + + + + {% endfor %} +
Gerente InterlegisUFNúmero de casas
{{ linha.gerente.nome_completo }} {{ uf.1 }}{{ uf.2.count }}
Total de casas atendidas por {{ linha.gerente.nome_completo }}{{ linha.gerente.casas_que_gerencia.count }}
+ + + + diff --git a/sigi/apps/casas/urls.py b/sigi/apps/casas/urls.py index 9d73253..38f0687 100644 --- a/sigi/apps/casas/urls.py +++ b/sigi/apps/casas/urls.py @@ -52,4 +52,6 @@ urlpatterns = patterns( # Atualização por CSV url(r'^orgao/importa/$', login_required(importa_casas.as_view()), name='importar-casas'), + url(r'^gerentes/$', 'gerentes_interlegis', + name='gerentes_interlegis'), ) diff --git a/sigi/apps/casas/views.py b/sigi/apps/casas/views.py index ffb289f..694e84b 100644 --- a/sigi/apps/casas/views.py +++ b/sigi/apps/casas/views.py @@ -1035,3 +1035,65 @@ def painel_relacionamento(request): return render(request, 'casas/resumo_carteira_snippet.html', context) return render(request, 'casas/painel.html', context) + +@login_required +def gerentes_interlegis(request): + formato = request.GET.get('fmt', 'html') + inclui_casas = (request.GET.get('casas', 'no') == 'yes') + gerentes = Servidor.objects.exclude( + casas_que_gerencia=None).select_related('casas_que_gerencia') + dados = [] + for gerente in gerentes: + row = {'gerente': gerente, 'ufs': []} + for uf in (gerente.casas_que_gerencia.distinct('municipio__uf__sigla') + .order_by('municipio__uf__sigla') + .values_list('municipio__uf__sigla', 'municipio__uf__nome') + ): + row['ufs'].append(( + uf[0], + uf[1], + gerente.casas_que_gerencia.filter(municipio__uf__sigla=uf[0]) + )) + dados.append(row) + + if formato == 'pdf': + return render_to_pdf( + 'casas/gerentes_interlegis_pdf.html', + {'gerentes': dados} + ) + elif formato == 'csv': + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = ('attachment; ' + 'filename="gerentes_interlegis.csv"') + fieldnames = ['gerente', 'total_casas', 'uf', 'total_casas_uf'] + if inclui_casas: + fieldnames.append('casa_legislativa') + writer = csv.DictWriter(response, fieldnames=fieldnames) + writer.writeheader() + for linha in dados: + rec = { + 'gerente': linha['gerente'].nome_completo.encode('utf8'), + 'total_casas': linha['gerente'].casas_que_gerencia.count() + } + for uf in linha['ufs']: + rec['uf'] = uf[1].encode('utf8') + rec['total_casas_uf'] = uf[2].count() + if inclui_casas: + for casa in uf[2]: + rec['casa_legislativa'] = casa.nome.encode('utf8') + writer.writerow(rec) + rec['gerente'] = '' + rec['total_casas'] = '' + rec['uf'] = '' + rec['total_casas_uf'] = '' + else: + writer.writerow(rec) + rec['gerente'] = '' + rec['total_casas'] = '' + return response + + return render( + request, + 'casas/gerentes_interlegis.html', + {'gerentes': dados} + ) diff --git a/sigi/apps/home/templatetags/menu_conf.yaml b/sigi/apps/home/templatetags/menu_conf.yaml index 271306a..0c51f7e 100644 --- a/sigi/apps/home/templatetags/menu_conf.yaml +++ b/sigi/apps/home/templatetags/menu_conf.yaml @@ -23,6 +23,8 @@ main_menu: url: casas/carteira - title: Organizar relacionamentos url: casas/portfolio/ + - title: Lista de gerentes + url: casas/gerentes/ - title: Convênios children: - title: Convênios