Browse Source

Merge pull request #185 from lucasmndc/sigi-4.0

Conversão para ReportListView
sigi-4.0
Sesostris Vieira 4 weeks ago
committed by GitHub
parent
commit
13a7c1f831
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 52
      sigi/apps/casas/views.py
  2. 2
      sigi/apps/espacos/templates/espacos/agenda.html
  3. 8
      sigi/apps/espacos/templates/espacos/uso_espaco.html
  4. 50
      sigi/apps/espacos/views.py

52
sigi/apps/casas/views.py

@ -447,9 +447,24 @@ class CnpjErradoReport(
return Orgao._meta return Orgao._meta
class GerentesListView(PermissionRequiredMixin, ListView): class GerentesListView(PermissionRequiredMixin, ReportListView):
template_name = "admin/casas/gerentes_list.html" template_name = "admin/casas/gerentes_list.html"
_tipos = None _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): def get_tipos(self):
if self._tipos is None: if self._tipos is None:
@ -465,39 +480,40 @@ class GerentesListView(PermissionRequiredMixin, ListView):
return self.request.user.is_staff return self.request.user.is_staff
def get_queryset(self): 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) regioes_dict = dict(UnidadeFederativa.REGIAO_CHOICES)
counters = { counters = {
f"c_{t}": Count("id", filter=Q(tipo__id=t)) f"c_{t}": Count("id", filter=Q(tipo__id=t))
for t in self.get_tipos() for t in self.get_tipos()
} }
gerentes = list( gerentes = list(
Servidor.objects.exclude(casas_que_gerencia=None) self.get_queryset().annotate(tot_casas=Count("casas_que_gerencia"))
.order_by("nome_completo")
.annotate(tot_casas=Count("casas_que_gerencia"))
) )
for gerente in gerentes: for gerente in gerentes:
regioes = [ regioes = []
( for r, t in (
regioes_dict[r], gerente.casas_que_gerencia.order_by("municipio__uf__regiao")
t, .values_list("municipio__uf__regiao")
.annotate(tot_casas=Count("*"))
):
ufs = (
gerente.casas_que_gerencia.filter(municipio__uf__regiao=r) gerente.casas_que_gerencia.filter(municipio__uf__regiao=r)
.order_by("municipio__uf__nome") .order_by("municipio__uf__nome")
.values_list("municipio__uf__sigla", "municipio__uf__nome") .values_list("municipio__uf__sigla", "municipio__uf__nome")
.annotate(tot_casas=Count("*")) .annotate(tot_casas=Count("*"))
.annotate(**counters), .annotate(**counters)
) )
for r, t in gerente.casas_que_gerencia.order_by( regioes.append((regioes_dict[r], t, list(ufs)))
"municipio__uf__regiao"
)
.values_list("municipio__uf__regiao")
.annotate(tot_casas=Count("*"))
]
setattr(gerente, "regioes", regioes) setattr(gerente, "regioes", regioes)
return gerentes
def get_context_data(self, **kwargs): context["object_list"] = gerentes
context = super().get_context_data(**kwargs)
context["tipos_orgao"] = TipoOrgao.objects.filter( context["tipos_orgao"] = TipoOrgao.objects.filter(
id__in=self.get_tipos() id__in=self.get_tipos()
).order_by("id") ).order_by("id")

2
sigi/apps/espacos/templates/espacos/agenda.html

@ -50,7 +50,7 @@
</div> </div>
<div class="card-footer d-flex justify-content-end"> <div class="card-footer d-flex justify-content-end">
<div> <div>
<a class="btn btn-primary" role="button" href="?ano={{ ano_pesquisa|safe }}&mes={{ mes_pesquisa|safe }}&pdf=1" title="{% trans 'Exportar para PDF' %}">{% icon "pdf" %} {% trans 'Exportar para PDF' %}</a> <a class="btn btn-primary" role="button" href="?ano={{ ano_pesquisa|safe }}&mes={{ mes_pesquisa|safe }}&fmt=pdf" title="{% trans 'Exportar para PDF' %}">{% icon "pdf" %} {% trans 'Exportar para PDF' %}</a>
</div> </div>
</div> </div>
</div> </div>

8
sigi/apps/espacos/templates/espacos/uso_espaco.html

@ -12,7 +12,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<form> <form method="get" action="">
<div class="card mb-3"> <div class="card mb-3">
<div class="card-header"> <div class="card-header">
<a class="icon-link" data-bs-toggle="collapse" href="#filterFormCollapse" aria-expanded="{% if reservas %}false{% else %}true{% endif %}" aria-controls="filterFormCollapse"> <a class="icon-link" data-bs-toggle="collapse" href="#filterFormCollapse" aria-expanded="{% if reservas %}false{% else %}true{% endif %}" aria-controls="filterFormCollapse">
@ -25,10 +25,10 @@
<div class="card-footer d-flex justify-content-end"> <div class="card-footer d-flex justify-content-end">
<div> <div>
<button type="submit" class="btn btn-primary">{% trans 'Visualizar' %}</button> <button type="submit" class="btn btn-primary">{% trans 'Visualizar' %}</button>
<button type="submit" name="pdf" value="1" class="btn btn-primary" title="{% trans 'Exportar para PDF' %}"> <a href="?{{ request.GET.urlencode }}&fmt=pdf" class="btn btn-primary" title="{% trans 'Exportar para PDF' %}">
{% icon "pdf" %} {% icon "pdf" %}
{% trans 'Exportar para PDF' %} {% trans 'Exportar para PDF' %}
</button> </a>
</div> </div>
</div> </div>
</div> </div>
@ -54,4 +54,4 @@
</div> </div>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

50
sigi/apps/espacos/views.py

@ -17,11 +17,31 @@ from sigi.apps.utils.mixins import ReportViewMixin, StaffMemberRequiredMixin
from sigi.apps.utils.views import ReportListView from sigi.apps.utils.views import ReportListView
class Agenda(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): class Agenda(StaffMemberRequiredMixin, ReportListView):
html_template_name = "espacos/agenda.html" template_name = "espacos/agenda.html"
pdf_template_name = "espacos/agenda_pdf.html" template_name_pdf = "espacos/agenda_pdf.html"
report_title = _("Reserva de espaços do ILB") report_title = _("Reserva de espaços do ILB")
pagesize = "A4 landscape" 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): def get_context_data(self, **kwargs):
mes_pesquisa = int( mes_pesquisa = int(
@ -135,11 +155,29 @@ class Agenda(ReportViewMixin, StaffMemberRequiredMixin, TemplateView):
return context return context
class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): class UsoEspacos(StaffMemberRequiredMixin, ReportListView):
html_template_name = "espacos/uso_espaco.html" template_name = "espacos/uso_espaco.html"
pdf_template_name = "espacos/uso_espaco_pdf.html" template_name_pdf = "espacos/uso_espaco_pdf.html"
report_title = _("Uso dos espaços - Auditórios e Salas") report_title = _("Uso dos espaços - Auditórios e Salas")
pagesize = "A4 landscape" 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): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)

Loading…
Cancel
Save