Browse Source

Ajustes no relatório. Compl. Gertiq #160526

pull/169/head 3.0.62
Sesóstris Vieira 1 year ago
parent
commit
a72017e1ec
  1. 20
      sigi/apps/espacos/forms.py
  2. 8
      sigi/apps/espacos/templates/espacos/snippets/uso_espaco_snippet.html
  3. 21
      sigi/apps/espacos/templates/espacos/uso_espaco.html
  4. 22
      sigi/apps/espacos/templates/espacos/uso_espaco_pdf.html
  5. 45
      sigi/apps/espacos/views.py

20
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):

8
sigi/apps/espacos/templates/espacos/snippets/uso_espaco_snippet.html

@ -3,8 +3,10 @@
<table class="calendar-table" repeat="2">
<thead>
<tr>
{% if not espacos %}
<th rowspan="2">{% trans "Espaço" %}</th>
{% endif %}
<th rowspan="2">{% trans "SIGAD" %}</th>
<th rowspan="2">{% trans "Data pedido" %}</th>
<th rowspan="2">{% trans "Virtual" %}</th>
<th rowspan="2">{% trans "Data início" %}</th>
<th rowspan="2">{% trans "Data término" %}</th>
@ -23,8 +25,10 @@
<tbody>
{% for reserva in reservas %}
<tr>
{% if not espacos %}
<th>{{ reserva.espaco.nome }}</th>
{% endif %}
<td>{{ reserva.num_processo }}</td>
<td>{{ reserva.data_pedido|default:"-" }}</td>
<td>{{ reserva.virtual|yesno }}</td>
<td>{{ reserva.inicio }}</td>
<td>{{ reserva.termino }}</td>

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

@ -39,18 +39,31 @@
</form>
</div>
</div>
{% for espaco in espacos %}
{% if espacos %}
{% for espaco in espacos %}
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<span class="card-title">{{ espaco.nome }}</span>
{% include "espacos/snippets/uso_espaco_snippet.html" with reservas=espaco.reservas %}
</div>
</div>
</div>
</div>
{% endfor %}
{% else %}
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<span class="card-title">{{ espaco.nome }}</span>
{% include "espacos/snippets/uso_espaco_snippet.html" with reservas=espaco.reservas %}
{% include "espacos/snippets/uso_espaco_snippet.html" %}
</div>
</div>
</div>
</div>
{% endfor %}
{% endif %}
{% endblock %}
{% block footer %}

22
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 %}
<h4>
{% blocktranslate%}Semana de {{ data_inicio }} a {{ data_termino }}{% endblocktranslate %}
</h4>
<h5>{{ espaco.nome }}</h5>
<br/>
{% include "espacos/snippets/uso_espaco_snippet.html" with reservas=espaco.reservas %}
{% if not forloop.last %}
<div class="new-page"></div>
{% endif %}
{% endfor %}
{% else %}
<h4>
{% blocktranslate%}Semana de {{ data_inicio }} a {{ data_termino }}{% endblocktranslate %}
</h4>
<h5>{{ espaco.nome }}</h5>
<br/>
{% include "espacos/snippets/uso_espaco_snippet.html" with reservas=espaco.reservas %}
{% if not forloop.last %}
<div class="new-page"></div>
{% endif %}
{% endfor %}
{% include "espacos/snippets/uso_espaco_snippet.html" %}
{% endif %}
{% endblock %}

45
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,

Loading…
Cancel
Save