From 09c4860f70c6b6be87b7fdc4d0ce2a7bcff85bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Wed, 29 Nov 2023 17:12:44 -0300 Subject: [PATCH] =?UTF-8?q?Ajustes=20no=20relat=C3=B3rio=20de=20uso=20de?= =?UTF-8?q?=20espa=C3=A7os.=20Compl.=20Gertiq=20#160526?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/espacos/forms.py | 11 ++++--- .../espacos/snippets/uso_espaco_snippet.html | 4 --- .../espacos/templates/espacos/uso_espaco.html | 15 +++++---- .../templates/espacos/uso_espaco_pdf.html | 16 ++++++--- sigi/apps/espacos/views.py | 33 +++++++++++-------- 5 files changed, 46 insertions(+), 33 deletions(-) diff --git a/sigi/apps/espacos/forms.py b/sigi/apps/espacos/forms.py index 7d2e8d2..9636e68 100644 --- a/sigi/apps/espacos/forms.py +++ b/sigi/apps/espacos/forms.py @@ -11,11 +11,12 @@ class UsoEspacoReportForm(forms.Form): class Media: css = {"all": ["css/change_form.css"]} js = [ - "/admin/js/vendor/select2/select2.full.js", - "/admin/js/change_form.js", - "/admin/js/vendor/select2/i18n/pt-BR.js", - "/material/admin/js/widgets/TimeInput.js", - "/admin/js/core.js", + "admin/js/vendor/select2/select2.full.js", + "admin/js/change_form.js", + "admin/js/vendor/select2/i18n/pt-BR.js", + "material/admin/js/widgets/TimeInput.js", + "admin/js/core.js", + "/admin/jsi18n/", ] def get_semana(self): diff --git a/sigi/apps/espacos/templates/espacos/snippets/uso_espaco_snippet.html b/sigi/apps/espacos/templates/espacos/snippets/uso_espaco_snippet.html index 55f4d68..b760cf6 100644 --- a/sigi/apps/espacos/templates/espacos/snippets/uso_espaco_snippet.html +++ b/sigi/apps/espacos/templates/espacos/snippets/uso_espaco_snippet.html @@ -3,7 +3,6 @@ - @@ -24,9 +23,6 @@ {% for reserva in reservas %} - {% ifchanged reserva.espaco %} - - {% endifchanged %} diff --git a/sigi/apps/espacos/templates/espacos/uso_espaco.html b/sigi/apps/espacos/templates/espacos/uso_espaco.html index c898fab..d62686d 100644 --- a/sigi/apps/espacos/templates/espacos/uso_espaco.html +++ b/sigi/apps/espacos/templates/espacos/uso_espaco.html @@ -39,15 +39,18 @@ -
-
-
-
- {% include "espacos/snippets/uso_espaco_snippet.html" %} + {% for espaco in espacos %} +
+
+
+
+ {{ espaco.nome }} + {% include "espacos/snippets/uso_espaco_snippet.html" with reservas=espaco.reservas %} +
-
+ {% endfor %} {% endblock %} {% block footer %} diff --git a/sigi/apps/espacos/templates/espacos/uso_espaco_pdf.html b/sigi/apps/espacos/templates/espacos/uso_espaco_pdf.html index 04d7379..470ba77 100644 --- a/sigi/apps/espacos/templates/espacos/uso_espaco_pdf.html +++ b/sigi/apps/espacos/templates/espacos/uso_espaco_pdf.html @@ -11,9 +11,15 @@ {% endblock %} {% block main_content %} -

- {% blocktranslate%}Semana de {{ data_inicio }} a {{ data_termino }}{% endblocktranslate %} -

-
- {% include "espacos/snippets/uso_espaco_snippet.html" %} + {% for espaco in espacos %} +

+ {% blocktranslate%}Semana de {{ data_inicio }} a {{ data_termino }}{% endblocktranslate %} +

+
{{ espaco.nome }}
+
+ {% include "espacos/snippets/uso_espaco_snippet.html" with reservas=espaco.reservas %} + {% if not forloop.last %} +
+ {% endif %} + {% endfor %} {% endblock %} \ No newline at end of file diff --git a/sigi/apps/espacos/views.py b/sigi/apps/espacos/views.py index 83ea050..cc023d7 100644 --- a/sigi/apps/espacos/views.py +++ b/sigi/apps/espacos/views.py @@ -2,7 +2,7 @@ import calendar import locale from typing import Any from django import http -from django.db.models import Q, Count +from django.db.models import Q, Count, Prefetch from django.utils import timezone from django.utils.translation import ( to_locale, @@ -109,7 +109,7 @@ class Agenda(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): html_template_name = "espacos/uso_espaco.html" pdf_template_name = "espacos/uso_espaco_pdf.html" - report_title = _("Uso dos espaços") + report_title = _("Uso dos espaços - Auditórios e Salas") pagesize = "A4 landscape" def get_context_data(self, **kwargs): @@ -130,27 +130,34 @@ class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): if not sel_espacos: sel_espacos = Espaco.objects.all() - reservas = ( - Reserva.objects.filter( - status=Reserva.STATUS_ATIVO, espaco__in=sel_espacos - ) + reservas_qs = ( + Reserva.objects.filter(status=Reserva.STATUS_ATIVO) .filter( Q(inicio__range=(data_inicio, data_fim)) | Q(termino__range=(data_inicio, data_fim)) ) - .order_by("espaco", "inicio", "termino") + .order_by("inicio", "termino") ) - rowspans = dict( - reservas.order_by("espaco") - .values_list("espaco") - .annotate(Count("espaco")) + espacos = ( + sel_espacos.filter(reserva__status=Reserva.STATUS_ATIVO) + .filter( + Q(reserva__inicio__range=(data_inicio, data_fim)) + | Q(reserva__termino__range=(data_inicio, data_fim)) + ) + .distinct() + .prefetch_related( + Prefetch( + "reserva_set", + queryset=reservas_qs, + to_attr="reservas", + ) + ) ) context = super().get_context_data(**kwargs) context.update( { - "reservas": reservas, - "rowspans": rowspans, + "espacos": espacos, "form": form, "data_inicio": data_inicio, "data_termino": data_fim,
{% trans "Espaço" %} {% trans "SIGAD" %} {% trans "Data pedido" %} {% trans "Virtual" %}
{{ reserva.espaco.nome }}{{ reserva.num_processo }} {{ reserva.data_pedido|default:"-" }} {{ reserva.virtual|yesno }}