From 7d180dded1ef0a69709d53f2b106b53cbaecd6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 2 Mar 2023 11:14:23 -0300 Subject: [PATCH] Lista de Gerentes Interlegis --- sigi/apps/casas/admin_urls.py | 1 + .../templates/admin/casas/gerentes_list.html | 93 +++++++++++++++++++ sigi/apps/casas/views.py | 72 +++++++++++++- sigi/menu_conf.yaml | 2 +- 4 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 sigi/apps/casas/templates/admin/casas/gerentes_list.html diff --git a/sigi/apps/casas/admin_urls.py b/sigi/apps/casas/admin_urls.py index 1d5e66f..455b634 100644 --- a/sigi/apps/casas/admin_urls.py +++ b/sigi/apps/casas/admin_urls.py @@ -3,4 +3,5 @@ from sigi.apps.casas import views urlpatterns = [ path("carteira/", views.painel_relacionamento, name="casas_carteira"), + path("gerentes/", views.GerentesListView.as_view(), name="casas_gerentes"), ] diff --git a/sigi/apps/casas/templates/admin/casas/gerentes_list.html b/sigi/apps/casas/templates/admin/casas/gerentes_list.html new file mode 100644 index 0000000..d16e5c3 --- /dev/null +++ b/sigi/apps/casas/templates/admin/casas/gerentes_list.html @@ -0,0 +1,93 @@ +{% extends 'public/base_site.html' %} +{% load i18n static %} + +{% block extrastyle %} + {{ block.super }} + +{% endblock extrastyle %} + +{% block content %} + {{ block.super }} + {% for gerente in object_list %} +
+
+
+
+
+
+ {% if gerente.foto %} + + {% else %} + account_circle + {% endif %} +
+
+ + {{ gerente.nome_completo }} +

+ + {% blocktrans with total=gerente.tot_casas %} + Atende a {{ total }} casas legislativas. + + {% endblocktrans %} +

+
+
+
+ + {% for regiao, tot_casas, ufs in gerente.regioes %} +
+ + {{ regiao }} + +

+ + {% blocktrans with total=tot_casas %} + {{ total }} casas atendidas + {% endblocktrans %} + +

+ + + + + + {% for tipo in tipos_orgao %} + + {% endfor %} + + + + {% for uf_rec in ufs %} + + {% for value in uf_rec|slice:"1:" %} + {% if forloop.first %} + + {% else %} + + {% endif %} + {% endfor %} + + {% endfor %} + +
{% trans "Unidade da Federação" %}{% trans "Total de Casas" %}{{ tipo.nome }}
+ + {{ value }} + + + {% if forloop.counter > 2 and value > 0 %} + + {{ value }} + + {% else %} + {{ value|default:"-" }} + {% endif %} +
+
+ {% endfor %} +
+
+
+
+ {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/sigi/apps/casas/views.py b/sigi/apps/casas/views.py index 9d70550..d6f2065 100644 --- a/sigi/apps/casas/views.py +++ b/sigi/apps/casas/views.py @@ -5,15 +5,24 @@ from django.contrib.admin.sites import site from django.contrib.admin.views.decorators import staff_member_required from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required -from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.auth.mixins import ( + LoginRequiredMixin, + PermissionRequiredMixin, +) from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render, get_object_or_404 from django.urls import reverse_lazy from django.utils.translation import gettext as _ -from django.views.generic import CreateView, DeleteView, ListView, UpdateView +from django.views.generic import ( + CreateView, + DeleteView, + ListView, + UpdateView, + DetailView, +) from sigi.apps.casas.forms import FuncionarioForm -from sigi.apps.casas.models import Funcionario, Orgao +from sigi.apps.casas.models import Funcionario, Orgao, TipoOrgao from sigi.apps.home.mixins import ContatoInterlegisViewMixin from sigi.apps.servidores.models import Servidor from sigi.apps.contatos.models import ( @@ -321,6 +330,63 @@ def painel_relacionamento(request): return render(request, "casas/painel.html", context) +class GerentesListView(PermissionRequiredMixin, ListView): + template_name = "admin/casas/gerentes_list.html" + _tipos = None + + def get_tipos(self): + if self._tipos is None: + self._tipos = ( + Orgao.objects.exclude(gerentes_interlegis=None) + .order_by("tipo_id") + .distinct("tipo") + .values_list("tipo", flat=True) + ) + return self._tipos + + def has_permission(self): + return self.request.user.is_staff + + def get_queryset(self): + regioes_dict = dict(UnidadeFederativa.REGIAO_CHOICES) + counters = { + f"c_{t}": Count("id", filter=Q(tipo__id=t)) + for t in self.get_tipos() + } + gerentes = list( + Servidor.objects.exclude(casas_que_gerencia=None) + .order_by("nome_completo") + .annotate(tot_casas=Count("casas_que_gerencia")) + ) + + for gerente in gerentes: + regioes = [ + ( + regioes_dict[r], + t, + gerente.casas_que_gerencia.filter(municipio__uf__regiao=r) + .order_by("municipio__uf__nome") + .values_list("municipio__uf__sigla", "municipio__uf__nome") + .annotate(tot_casas=Count("*")) + .annotate(**counters), + ) + for r, t in gerente.casas_que_gerencia.order_by( + "municipio__uf__regiao" + ) + .values_list("municipio__uf__regiao") + .annotate(tot_casas=Count("*")) + ] + setattr(gerente, "regioes", regioes) + return gerentes + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["tipos_orgao"] = TipoOrgao.objects.filter( + id__in=self.get_tipos() + ).order_by("id") + return context + + ################################################################################ # Views para site público - acesso dos contatos Interlegis # ################################################################################ diff --git a/sigi/menu_conf.yaml b/sigi/menu_conf.yaml index 39b637e..84ebf54 100644 --- a/sigi/menu_conf.yaml +++ b/sigi/menu_conf.yaml @@ -48,7 +48,7 @@ main_menu: - title: Organizar relacionamentos view_name: - title: Lista de gerentes - view_name: + view_name: casas_gerentes - title: Convênios icon: assignment children: