Browse Source

Adiciona resumo de reserva de espaços. Gertiq #160539

pull/177/head
Sesostris Vieira 6 months ago
parent
commit
84a101c678
  1. 5
      sigi/apps/espacos/admin_urls.py
  2. 14
      sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report.html
  3. 64
      sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_items_snippet.html
  4. 39
      sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_pdf.html
  5. 66
      sigi/apps/espacos/views.py

5
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",
),
]

14
sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report.html

@ -0,0 +1,14 @@
{% extends "utils/report/report.html" %}
{% block extrastyle %}
{{ block.super }}
<style type="text/css">
.cellnumber {
text-align: right;
}
</style>
{% endblock %}
{% block data %}
{% include "espacos/report/resumo_reservas_report/report_items_snippet.html" with mode="html" %}
{% endblock data %}

64
sigi/apps/espacos/templates/espacos/report/resumo_reservas_report/report_items_snippet.html

@ -0,0 +1,64 @@
{% load i18n admin_urls sigi_tags %}
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<table class="striped">
<colgroup>
<col />
<col class="cellnumber"/>
<col class="cellnumber"/>
<col class="cellnumber"/>
<col class="cellnumber"/>
</colgroup>
<thead>
<tr>
<th rowspan="2">{% translate "Espaço" %}</th>
<th colspan="2">{% translate "Número de reservas" %}</th>
<th colspan="2">{% translate "Número de participantes" %}</th>
</tr>
<tr>
<th>{% translate "Total" %}</th>
<th>{% translate "Vinculadas a eventos Interlegis" %}</th>
<th>{% translate "Total" %}</th>
<th>{% translate "Média por reserva" %}</th>
</thead>
<tbody>
{% for obj in object_list %}
{% if break_field %}
{% with obj|valueof:break_field as monitor_break %}
{% ifchanged monitor_break %}
<tr><th colspan="{{ list_fields|length }}">{{ monitor_break }}</th></tr>
{% endifchanged %}
{% endwith %}
{% endif %}
<tr{% if change_field %}{% with obj|valueof:change_field as monitor_change %}{% ifchanged monitor_change %} class="changed {{ change_field }}-changed"{% endifchanged %}{% endwith %}{% endif %}>
{% for field_name in list_fields %}
<td {% if not forloop.first %}class="cellnumber"{% endif %}>
{% if field_name in link_fields %}
<a href="{% url opts|admin_urlname:'change' obj.pk %}">
{{ obj|valueof:field_name|safe }}
</a>
{% else %}
{% if forloop.last %}
{{ obj|valueof:field_name|floatformat:2|safe }}
{% else %}
{{ obj|valueof:field_name|safe }}
{% endif %}
{% endif %}
</td>
{% endfor %}
</tr>
{% empty %}
<tr>
<td colspam="{{ list_labels|length }}">
{{ empty_message }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>

39
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 %}
<div class="card">
<h5>Filtros</h5>
<table>
<tr>
<th>{% translate "Período" %}</th>
<td>
{% blocktranslate with data_inicio=form.data.data_inicio data_fim=form.data.data_fim %}
de {{ data_inicio }} a {{ data_fim }}
{% endblocktranslate %}
</td>
</tr>
{% if form.virtual != "A" %}
<tr>
<th>{% translate "Modo" %}</th>
<td>
{% if form.virtual == "V" %}
{% translate "Apenas virtual" %}
{% else %}
{% translate "Apenas presencial" %}
{% endif %}
</td>
</tr>
{% endif %}
</div>
{% include "espacos/report/resumo_reservas_report/report_items_snippet.html" %}
{% endblock %}

66
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

Loading…
Cancel
Save