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): 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: class Media:
css = {"all": ["css/change_form.css"]} css = {"all": ["css/change_form.css"]}
js = [ js = [
@ -34,8 +43,17 @@ class UsoEspacoReportForm(forms.Form):
data_fim = forms.DateField( data_fim = forms.DateField(
label=_("Data fim"), required=True, widget=MaterialAdminDateWidget 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( 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): 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"> <table class="calendar-table" repeat="2">
<thead> <thead>
<tr> <tr>
{% if not espacos %}
<th rowspan="2">{% trans "Espaço" %}</th>
{% endif %}
<th rowspan="2">{% trans "SIGAD" %}</th> <th rowspan="2">{% trans "SIGAD" %}</th>
<th rowspan="2">{% trans "Data pedido" %}</th>
<th rowspan="2">{% trans "Virtual" %}</th> <th rowspan="2">{% trans "Virtual" %}</th>
<th rowspan="2">{% trans "Data início" %}</th> <th rowspan="2">{% trans "Data início" %}</th>
<th rowspan="2">{% trans "Data término" %}</th> <th rowspan="2">{% trans "Data término" %}</th>
@ -23,8 +25,10 @@
<tbody> <tbody>
{% for reserva in reservas %} {% for reserva in reservas %}
<tr> <tr>
{% if not espacos %}
<th>{{ reserva.espaco.nome }}</th>
{% endif %}
<td>{{ reserva.num_processo }}</td> <td>{{ reserva.num_processo }}</td>
<td>{{ reserva.data_pedido|default:"-" }}</td>
<td>{{ reserva.virtual|yesno }}</td> <td>{{ reserva.virtual|yesno }}</td>
<td>{{ reserva.inicio }}</td> <td>{{ reserva.inicio }}</td>
<td>{{ reserva.termino }}</td> <td>{{ reserva.termino }}</td>

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

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

22
sigi/apps/espacos/templates/espacos/uso_espaco_pdf.html

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

45
sigi/apps/espacos/views.py

@ -111,6 +111,7 @@ class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView):
pdf_template_name = "espacos/uso_espaco_pdf.html" pdf_template_name = "espacos/uso_espaco_pdf.html"
report_title = _("Uso dos espaços - Auditórios e Salas") report_title = _("Uso dos espaços - Auditórios e Salas")
pagesize = "A4 landscape" pagesize = "A4 landscape"
attachment = False
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
form = UsoEspacoReportForm(self.request.GET) form = UsoEspacoReportForm(self.request.GET)
@ -118,6 +119,8 @@ class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView):
data_inicio = form.cleaned_data["data_inicio"] data_inicio = form.cleaned_data["data_inicio"]
data_fim = form.cleaned_data["data_fim"] data_fim = form.cleaned_data["data_fim"]
sel_espacos = form.cleaned_data["espaco"] sel_espacos = form.cleaned_data["espaco"]
virtual = form.cleaned_data["virtual"]
agrupar_espacos = form.cleaned_data["agrupar_espacos"]
else: else:
form = UsoEspacoReportForm( form = UsoEspacoReportForm(
initial={"espaco": Espaco.objects.all()} initial={"espaco": Espaco.objects.all()}
@ -125,39 +128,53 @@ class UsoEspacos(ReportViewMixin, StaffMemberRequiredMixin, TemplateView):
semana = form.get_semana() semana = form.get_semana()
data_inicio = semana["first"] data_inicio = semana["first"]
data_fim = semana["last"] data_fim = semana["last"]
virtual = UsoEspacoReportForm.VIRTUAL_ALL
agrupar_espacos = False
sel_espacos = None sel_espacos = None
if not sel_espacos: if not sel_espacos:
sel_espacos = Espaco.objects.all() 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 = ( reservas_qs = (
Reserva.objects.filter(status=Reserva.STATUS_ATIVO) Reserva.objects.filter(q_virtual, status=Reserva.STATUS_ATIVO)
.filter( .filter(
Q(inicio__range=(data_inicio, data_fim)) Q(inicio__range=(data_inicio, data_fim))
| Q(termino__range=(data_inicio, data_fim)) | Q(termino__range=(data_inicio, data_fim))
) )
.order_by("inicio", "termino") .order_by("inicio", "termino")
) )
espacos = (
sel_espacos.filter(reserva__status=Reserva.STATUS_ATIVO) if agrupar_espacos:
.filter( espacos = (
Q(reserva__inicio__range=(data_inicio, data_fim)) sel_espacos.filter(q_virtual, reserva__status=Reserva.STATUS_ATIVO)
| Q(reserva__termino__range=(data_inicio, data_fim)) .filter(
) Q(reserva__inicio__range=(data_inicio, data_fim))
.distinct() | Q(reserva__termino__range=(data_inicio, data_fim))
.prefetch_related( )
Prefetch( .distinct()
"reserva_set", .prefetch_related(
queryset=reservas_qs, Prefetch(
to_attr="reservas", "reserva_set",
queryset=reservas_qs,
to_attr="reservas",
)
) )
) )
) else:
espacos = None
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context.update( context.update(
{ {
"espacos": espacos, "espacos": espacos,
"reservas": reservas_qs,
"form": form, "form": form,
"data_inicio": data_inicio, "data_inicio": data_inicio,
"data_termino": data_fim, "data_termino": data_fim,

Loading…
Cancel
Save