From 6b9e0daaf985b6e2f1b3864f473d94a326eb67ea Mon Sep 17 00:00:00 2001 From: lucasmndc Date: Thu, 13 Feb 2025 13:35:51 -0300 Subject: [PATCH] =?UTF-8?q?Convers=C3=A3o=20para=20ReportListView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/casas/views.py | 52 ++++++++++++------- .../espacos/templates/espacos/agenda.html | 2 +- .../espacos/templates/espacos/uso_espaco.html | 8 +-- sigi/apps/espacos/views.py | 50 +++++++++++++++--- 4 files changed, 83 insertions(+), 29 deletions(-) diff --git a/sigi/apps/casas/views.py b/sigi/apps/casas/views.py index e18bfb8..4b175a0 100644 --- a/sigi/apps/casas/views.py +++ b/sigi/apps/casas/views.py @@ -447,9 +447,24 @@ class CnpjErradoReport( return Orgao._meta -class GerentesListView(PermissionRequiredMixin, ListView): +class GerentesListView(PermissionRequiredMixin, ReportListView): template_name = "admin/casas/gerentes_list.html" _tipos = None + list_fields = [ + "id", + "nome_completo", + "tot_casas", + "regioes_formatadas", + ] + list_labels = [ + "ID", + "Nome", + "Total de Casas", + "Casas Atendidas por Região", + ] + filter_form = None + report_title = "Lista de Gerentes" + model = Servidor def get_tipos(self): if self._tipos is None: @@ -465,39 +480,40 @@ class GerentesListView(PermissionRequiredMixin, ListView): return self.request.user.is_staff def get_queryset(self): + return Servidor.objects.exclude(casas_que_gerencia=None).order_by( + "nome_completo" + ) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) 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")) + self.get_queryset().annotate(tot_casas=Count("casas_que_gerencia")) ) for gerente in gerentes: - regioes = [ - ( - regioes_dict[r], - t, + regioes = [] + for r, t in ( + gerente.casas_que_gerencia.order_by("municipio__uf__regiao") + .values_list("municipio__uf__regiao") + .annotate(tot_casas=Count("*")) + ): + ufs = ( 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), + .annotate(**counters) ) - for r, t in gerente.casas_que_gerencia.order_by( - "municipio__uf__regiao" - ) - .values_list("municipio__uf__regiao") - .annotate(tot_casas=Count("*")) - ] + regioes.append((regioes_dict[r], t, list(ufs))) + setattr(gerente, "regioes", regioes) - return gerentes - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) + context["object_list"] = gerentes context["tipos_orgao"] = TipoOrgao.objects.filter( id__in=self.get_tipos() ).order_by("id") diff --git a/sigi/apps/espacos/templates/espacos/agenda.html b/sigi/apps/espacos/templates/espacos/agenda.html index 308435f..781213e 100644 --- a/sigi/apps/espacos/templates/espacos/agenda.html +++ b/sigi/apps/espacos/templates/espacos/agenda.html @@ -50,7 +50,7 @@ diff --git a/sigi/apps/espacos/templates/espacos/uso_espaco.html b/sigi/apps/espacos/templates/espacos/uso_espaco.html index 3a85903..d938674 100644 --- a/sigi/apps/espacos/templates/espacos/uso_espaco.html +++ b/sigi/apps/espacos/templates/espacos/uso_espaco.html @@ -12,7 +12,7 @@ {% endblock %} {% block content %} -
+ {% endif %} {% endif %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/sigi/apps/espacos/views.py b/sigi/apps/espacos/views.py index 94c6072..03798c1 100644 --- a/sigi/apps/espacos/views.py +++ b/sigi/apps/espacos/views.py @@ -17,11 +17,31 @@ from sigi.apps.utils.mixins import ReportViewMixin, StaffMemberRequiredMixin from sigi.apps.utils.views import ReportListView -class Agenda(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): - html_template_name = "espacos/agenda.html" - pdf_template_name = "espacos/agenda_pdf.html" +class Agenda(StaffMemberRequiredMixin, ReportListView): + template_name = "espacos/agenda.html" + template_name_pdf = "espacos/agenda_pdf.html" report_title = _("Reserva de espaços do ILB") pagesize = "A4 landscape" + model = Reserva + list_fields = [ + "espaco__nome", + "data_inicio", + "data_termino", + "hora_inicio", + "hora_termino", + "status", + ] + list_labels = [ + "Espaço", + "Data Início", + "Data Término", + "Hora Início", + "Hora Término", + "Status", + ] + + def get_list_labels(self): + return self.list_labels def get_context_data(self, **kwargs): mes_pesquisa = int( @@ -135,11 +155,29 @@ class Agenda(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): return context -class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): - html_template_name = "espacos/uso_espaco.html" - pdf_template_name = "espacos/uso_espaco_pdf.html" +class UsoEspacos(StaffMemberRequiredMixin, ReportListView): + template_name = "espacos/uso_espaco.html" + template_name_pdf = "espacos/uso_espaco_pdf.html" report_title = _("Uso dos espaços - Auditórios e Salas") pagesize = "A4 landscape" + model = Reserva + list_fields = [ + "espaco__nome", + "data_inicio", + "data_termino", + "virtual", + "status", + ] + list_labels = [ + "Espaço", + "Data Início", + "Data Término", + "Virtual", + "Status", + ] + + def get_list_labels(self): + return self.list_labels def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs)