From 5a1d7099f6d741a39985af01cc7800baa2d113b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 5 Oct 2023 10:34:11 -0300 Subject: [PATCH] =?UTF-8?q?adiciona=20campos=20n=C3=BAmero=20ACT=20e=20dat?= =?UTF-8?q?a=20Termino=20ACT=20do=20=C3=BAltimo=20ACT=20vigente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/eventos/admin.py | 62 +++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/sigi/apps/eventos/admin.py b/sigi/apps/eventos/admin.py index cb28c35..a0ea07a 100644 --- a/sigi/apps/eventos/admin.py +++ b/sigi/apps/eventos/admin.py @@ -1,8 +1,9 @@ import datetime import time from typing import Any +from django.db.models.query import QuerySet from moodle import Moodle -from django.db.models import Q +from django.db.models import Q, OuterRef, Subquery from django.conf import settings from django.contrib import admin, messages from django.core.exceptions import ValidationError @@ -19,6 +20,7 @@ from import_export.fields import Field from tinymce.models import HTMLField from tinymce.widgets import AdminTinyMCE from weasyprint import HTML +from sigi.apps.convenios.models import Convenio from sigi.apps.contatos.models import UnidadeFederativa from sigi.apps.eventos.models import ( Checklist, @@ -45,6 +47,23 @@ from sigi.apps.utils.mixins import ( ) +class ActVigenteFilter(admin.SimpleListFilter): + title = _("ACT vigente") + parameter_name = "act_vigente" + + def lookups(self, request, model_admin): + return ( + (("yes"), _("Yes")), + ("no", _("No")), + ) + + def queryset(self, request, queryset): + if self.value() == "yes": + return queryset.exclude(act_id=None) + if self.value() == "no": + return queryset.filter(act_id=None) + + class SolicitacaoResource(LabeledResourse): oficinas = Field(column_name="oficinas solicitadas") oficinas_uf = Field(column_name="número de oficinas realizadas na UF") @@ -240,6 +259,8 @@ class SolicitacaoAdmin(CartExportMixin, admin.ModelAdmin): "get_sigad_url", "status", "senador", + "get_act", + "get_data_termino_vigencia_act", "data_pedido", "data_recebido_coperi", "get_oficinas", @@ -257,6 +278,7 @@ class SolicitacaoAdmin(CartExportMixin, admin.ModelAdmin): "senador", "itemsolicitado__tipo_evento", "status", + ActVigenteFilter, ) list_select_related = ["casa", "casa__municipio", "casa__municipio__uf"] list_display_links = ("casa",) @@ -312,6 +334,26 @@ class SolicitacaoAdmin(CartExportMixin, admin.ModelAdmin): inlines = (ItemSolicitadoInline, AnexoSolicitacaoInline) autocomplete_fields = ("casa",) + def get_queryset(self, request): + acts = Convenio.objects.filter( + casa_legislativa=OuterRef("casa"), + projeto__sigla="ACT", + data_retorno_assinatura__lte=timezone.localdate(), + data_termino_vigencia__gte=timezone.localdate(), + ).order_by("data_termino_vigencia") + qs = self.model._default_manager.get_queryset() + qs = qs.annotate( + act_id=Subquery(acts.values("id")[:1]), + act_num=Subquery(acts.values("num_convenio")[:1]), + act_data_termino_vigencia=Subquery( + acts.values("data_termino_vigencia")[:1] + ), + ) + ordering = self.get_ordering(request) + if ordering: + qs = qs.order_by(*ordering) + return qs + def save_model(self, request, obj, form, change): if change: old_obj = Solicitacao.objects.get(id=obj.id) @@ -547,6 +589,24 @@ class SolicitacaoAdmin(CartExportMixin, admin.ModelAdmin): def get_populacao(self, obj): return obj.casa.municipio.populacao + @admin.display(description=_("ACT vigente"), ordering="act_num") + def get_act(self, obj): + if obj.act_id: + change_url = reverse( + "admin:convenios_convenio_change", args=[obj.act_id] + ) + return mark_safe( + f"" f"{obj.act_num}" + ) + return None + + @admin.display( + description=_("Término vigência ACT"), + ordering="act_data_termino_vigencia", + ) + def get_data_termino_vigencia_act(self, obj): + return obj.act_data_termino_vigencia + @admin.register(Funcao) class FuncaoAdmin(admin.ModelAdmin):