From 84a101c678a02b716d99305f80e39802468b4a9e Mon Sep 17 00:00:00 2001 From: Sesostris Vieira Date: Wed, 10 Jul 2024 14:08:16 -0300 Subject: [PATCH] =?UTF-8?q?Adiciona=20resumo=20de=20reserva=20de=20espa?= =?UTF-8?q?=C3=A7os.=20Gertiq=20#160539?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/espacos/admin_urls.py | 5 ++ .../report/resumo_reservas_report/report.html | 14 ++++ .../report_items_snippet.html | 64 ++++++++++++++++++ .../resumo_reservas_report/report_pdf.html | 39 +++++++++++ sigi/apps/espacos/views.py | 66 ++++++++++++++++++- 5 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report.html create mode 100644 sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_items_snippet.html create mode 100644 sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_pdf.html diff --git a/sigi/apps/espacos/admin_urls.py b/sigi/apps/espacos/admin_urls.py index 89e65ab..f0d4ed6 100644 --- a/sigi/apps/espacos/admin_urls.py +++ b/sigi/apps/espacos/admin_urls.py @@ -4,4 +4,9 @@ from sigi.apps.espacos import views urlpatterns = [ path("agenda/", views.Agenda.as_view(), name="espacos_agenda"), path("usoespacos/", views.UsoEspacos.as_view(), name="espacos_usoespaco"), + path( + "resumoreservas/", + views.ResumoReservasReport.as_view(), + name="espacos_resumoreservas", + ), ] diff --git a/sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report.html b/sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report.html new file mode 100644 index 0000000..3769387 --- /dev/null +++ b/sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report.html @@ -0,0 +1,14 @@ +{% extends "utils/report/report.html" %} + +{% block extrastyle %} + {{ block.super }} + +{% endblock %} + +{% block data %} + {% include "espacos/report/resumo_reservas_report/report_items_snippet.html" with mode="html" %} +{% endblock data %} diff --git a/sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_items_snippet.html b/sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_items_snippet.html new file mode 100644 index 0000000..e04dd0c --- /dev/null +++ b/sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_items_snippet.html @@ -0,0 +1,64 @@ +{% load i18n admin_urls sigi_tags %} +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + {% for obj in object_list %} + {% if break_field %} + {% with obj|valueof:break_field as monitor_break %} + {% ifchanged monitor_break %} + + {% endifchanged %} + {% endwith %} + {% endif %} + + {% for field_name in list_fields %} + + {% endfor %} + + {% empty %} + + + + {% endfor %} + +
{% translate "Espaço" %}{% translate "Número de reservas" %}{% translate "Número de participantes" %}
{% translate "Total" %}{% translate "Vinculadas a eventos Interlegis" %}{% translate "Total" %}{% translate "Média por reserva" %}
{{ monitor_break }}
+ {% if field_name in link_fields %} + + {{ obj|valueof:field_name|safe }} + + {% else %} + {% if forloop.last %} + {{ obj|valueof:field_name|floatformat:2|safe }} + {% else %} + {{ obj|valueof:field_name|safe }} + {% endif %} + {% endif %} +
+ {{ empty_message }} +
+
+
+
+
diff --git a/sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_pdf.html b/sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_pdf.html new file mode 100644 index 0000000..137d265 --- /dev/null +++ b/sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_pdf.html @@ -0,0 +1,39 @@ +{% extends "utils/report/report_pdf.html" %} +{% load static i18n %} + +{% block page_size %}A4 portrait{% endblock %} + +{% block extra_style %} + {{ block.super }} + .cellnumber { + text-align: right; + } +{% endblock %} + +{% block main_content %} +
+
Filtros
+ + + + + + {% if form.virtual != "A" %} + + + + + {% endif %} + + {% include "espacos/report/resumo_reservas_report/report_items_snippet.html" %} +{% endblock %} diff --git a/sigi/apps/espacos/views.py b/sigi/apps/espacos/views.py index 04234d2..e7fe409 100644 --- a/sigi/apps/espacos/views.py +++ b/sigi/apps/espacos/views.py @@ -2,7 +2,8 @@ import calendar import locale from typing import Any from django import http -from django.db.models import Q, Count, Prefetch +from django.contrib.auth.mixins import LoginRequiredMixin +from django.db.models import Q, Count, Sum, Avg, Prefetch from django.utils import timezone from django.utils.translation import ( to_locale, @@ -13,6 +14,7 @@ from django.views.generic.base import TemplateView from sigi.apps.espacos.models import Espaco, Reserva from sigi.apps.espacos.forms import UsoEspacoReportForm from sigi.apps.utils.mixins import ReportViewMixin, StaffMemberRequiredMixin +from sigi.apps.utils.views import ReportListView class Agenda(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): @@ -138,7 +140,6 @@ class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): pdf_template_name = "espacos/uso_espaco_pdf.html" report_title = _("Uso dos espaços - Auditórios e Salas") pagesize = "A4 landscape" - attachment = False def get_context_data(self, **kwargs): form = UsoEspacoReportForm(self.request.GET) @@ -212,3 +213,64 @@ class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): ) return context + + +class ResumoReservasReport( + LoginRequiredMixin, StaffMemberRequiredMixin, ReportListView +): + title = _("Resumo das reservas de espaços") + empty_message = _( + "Nenhuma reserva de espaço para os parâmetros solicitados" + ) + filter_form = UsoEspacoReportForm + queryset = Reserva.objects.all() + list_fields = [ + "espaco__nome", + "tot_reservas", + "tot_eventos", + "tot_participantes", + "media_participantes", + ] + list_labels = [ + "Espaço", + "Total de reservas", + "Vinculadas a eventos Interlegis", + "total de participantes", + "Média de participantes", + ] + + def get_queryset(self): + queryset = super().get_queryset() + queryset = ( + queryset.order_by("espaco__nome") + .values("espaco__nome") + .annotate( + tot_reservas=Count("id"), + tot_eventos=Count("evento"), + tot_participantes=Sum("total_participantes"), + media_participantes=Avg("total_participantes"), + ) + ) + return queryset + + def filter_queryset(self, queryset): + form = self.get_filter_form_instance() + if form: + if form.is_valid(): + filter = form.cleaned_data + else: + filter = self.filter_form_initials + if filter: + data_inicio = filter.get("data_inicio") + data_fim = filter.get("data_fim") + virtual = filter.get("virtual") + espaco = filter.get("espaco") + queryset = queryset.filter( + data_inicio__range=(data_inicio, data_fim) + ) + if virtual == UsoEspacoReportForm.VIRTUAL_VIRTUAL: + queryset = queryset.filter(virtual=True) + elif virtual == UsoEspacoReportForm.VIRTUAL_PRESENCIAL: + queryset = queryset.filter(virtual=False) + queryset = queryset.filter(espaco__in=espaco) + return queryset
{% translate "Período" %} + {% blocktranslate with data_inicio=form.data.data_inicio data_fim=form.data.data_fim %} + de {{ data_inicio }} a {{ data_fim }} + {% endblocktranslate %} +
{% translate "Modo" %} + {% if form.virtual == "V" %} + {% translate "Apenas virtual" %} + {% else %} + {% translate "Apenas presencial" %} + {% endif %} +