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 %} -