diff --git a/sigi/apps/espacos/forms.py b/sigi/apps/espacos/forms.py index 9636e68..b09af58 100644 --- a/sigi/apps/espacos/forms.py +++ b/sigi/apps/espacos/forms.py @@ -8,6 +8,15 @@ from sigi.apps.espacos.models import Espaco class UsoEspacoReportForm(forms.Form): + VIRTUAL_ALL = "A" + VIRTUAL_VIRTUAL = "V" + VIRTUAL_PRESENCIAL = "P" + VIRTUAL_CHOICES = ( + (VIRTUAL_ALL, _("All")), + (VIRTUAL_VIRTUAL, _("Apenas virtual")), + (VIRTUAL_PRESENCIAL, _("Apenas presencial")), + ) + class Media: css = {"all": ["css/change_form.css"]} js = [ @@ -34,8 +43,17 @@ class UsoEspacoReportForm(forms.Form): data_fim = forms.DateField( label=_("Data fim"), required=True, widget=MaterialAdminDateWidget ) + virtual = forms.ChoiceField( + label=_("Tipo de uso"), choices=VIRTUAL_CHOICES, initial=VIRTUAL_ALL + ) + agrupar_espacos = forms.BooleanField( + label=_("Agrupar por espaço"), required=False, initial=False + ) espaco = forms.ModelMultipleChoiceField( - label=_("Espaços"), required=True, queryset=Espaco.objects.all(), widget=CheckboxSelectMultiple + label=_("Espaços"), + required=True, + queryset=Espaco.objects.all(), + widget=CheckboxSelectMultiple, ) def __init__(self, *args, **kwargs): 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 b760cf6..208e220 100644 --- a/sigi/apps/espacos/templates/espacos/snippets/uso_espaco_snippet.html +++ b/sigi/apps/espacos/templates/espacos/snippets/uso_espaco_snippet.html @@ -3,8 +3,10 @@ + {% if not espacos %} + + {% endif %} - @@ -23,8 +25,10 @@ {% for reserva in reservas %} + {% if not espacos %} + + {% endif %} - diff --git a/sigi/apps/espacos/templates/espacos/uso_espaco.html b/sigi/apps/espacos/templates/espacos/uso_espaco.html index d62686d..35d5f30 100644 --- a/sigi/apps/espacos/templates/espacos/uso_espaco.html +++ b/sigi/apps/espacos/templates/espacos/uso_espaco.html @@ -39,18 +39,31 @@ - {% for espaco in espacos %} + + {% if espacos %} + {% for espaco in espacos %} +
+
+
+
+ {{ espaco.nome }} + {% include "espacos/snippets/uso_espaco_snippet.html" with reservas=espaco.reservas %} +
+
+
+
+ {% endfor %} + {% else %}
- {{ espaco.nome }} - {% include "espacos/snippets/uso_espaco_snippet.html" with reservas=espaco.reservas %} + {% include "espacos/snippets/uso_espaco_snippet.html" %}
- {% endfor %} + {% endif %} {% 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 470ba77..f879597 100644 --- a/sigi/apps/espacos/templates/espacos/uso_espaco_pdf.html +++ b/sigi/apps/espacos/templates/espacos/uso_espaco_pdf.html @@ -11,15 +11,23 @@ {% endblock %} {% block main_content %} - {% for espaco in espacos %} + {% if espacos %} + {% 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 %} + {% else %}

{% 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 %} + {% include "espacos/snippets/uso_espaco_snippet.html" %} + {% endif %} {% endblock %} \ No newline at end of file diff --git a/sigi/apps/espacos/views.py b/sigi/apps/espacos/views.py index cc023d7..50a39e2 100644 --- a/sigi/apps/espacos/views.py +++ b/sigi/apps/espacos/views.py @@ -111,6 +111,7 @@ 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) @@ -118,6 +119,8 @@ class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): data_inicio = form.cleaned_data["data_inicio"] data_fim = form.cleaned_data["data_fim"] sel_espacos = form.cleaned_data["espaco"] + virtual = form.cleaned_data["virtual"] + agrupar_espacos = form.cleaned_data["agrupar_espacos"] else: form = UsoEspacoReportForm( initial={"espaco": Espaco.objects.all()} @@ -125,39 +128,53 @@ class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView): semana = form.get_semana() data_inicio = semana["first"] data_fim = semana["last"] + virtual = UsoEspacoReportForm.VIRTUAL_ALL + agrupar_espacos = False sel_espacos = None if not sel_espacos: sel_espacos = Espaco.objects.all() + if virtual == UsoEspacoReportForm.VIRTUAL_VIRTUAL: + q_virtual = Q(virtual=True) + elif virtual == UsoEspacoReportForm.VIRTUAL_PRESENCIAL: + q_virtual = Q(virtual=False) + else: + q_virtual = Q() + reservas_qs = ( - Reserva.objects.filter(status=Reserva.STATUS_ATIVO) + Reserva.objects.filter(q_virtual, status=Reserva.STATUS_ATIVO) .filter( Q(inicio__range=(data_inicio, data_fim)) | Q(termino__range=(data_inicio, data_fim)) ) .order_by("inicio", "termino") ) - 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", + + if agrupar_espacos: + espacos = ( + sel_espacos.filter(q_virtual, 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", + ) ) ) - ) + else: + espacos = None context = super().get_context_data(**kwargs) context.update( { "espacos": espacos, + "reservas": reservas_qs, "form": form, "data_inicio": data_inicio, "data_termino": data_fim,
{% trans "Espaço" %}{% trans "SIGAD" %}{% trans "Data pedido" %} {% trans "Virtual" %} {% trans "Data início" %} {% trans "Data término" %}
{{ reserva.espaco.nome }}{{ reserva.num_processo }}{{ reserva.data_pedido|default:"-" }} {{ reserva.virtual|yesno }} {{ reserva.inicio }} {{ reserva.termino }}