From 3cdfc3da9fc3777365ebd8129a022903b938e60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Wed, 6 Dec 2023 15:57:49 -0300 Subject: [PATCH] =?UTF-8?q?Adiciona=20filtro=20de=20solicita=C3=A7=C3=B5es?= =?UTF-8?q?=20por=20microrregi=C3=A3o.=20Gertiq=20#169978?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/eventos/admin.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sigi/apps/eventos/admin.py b/sigi/apps/eventos/admin.py index 51520a9..bc07fbe 100644 --- a/sigi/apps/eventos/admin.py +++ b/sigi/apps/eventos/admin.py @@ -1,6 +1,7 @@ import datetime import pandas as pd import time +from admin_auto_filters.filters import AutocompleteFilter from moodle import Moodle from typing import Any from django.db import models @@ -37,7 +38,7 @@ 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.contatos.models import UnidadeFederativa, Municipio from sigi.apps.eventos.models import ( Checklist, Cronograma, @@ -105,6 +106,13 @@ class NumeroParticipantesFilter(admin.SimpleListFilter): ).filter(diferenca__gte=10) +class MicrorregiaoFilter(AutocompleteFilter): + title = _("Microrregião") + parameter_name = "casa__municipio__microrregiao__codigo_ibge__exact" + field_name = "microrregiao" + rel_model = Municipio + + class SolicitacaoResource(LabeledResourse): act_vigente = Field(column_name="ACT vigente") data_termino_act = Field(column_name="término vigência ACT") @@ -414,6 +422,7 @@ class SolicitacaoAdmin(AsciifyQParameter, CartExportMixin, admin.ModelAdmin): "itemsolicitado__tipo_evento", "status", ActVigenteFilter, + MicrorregiaoFilter, ) list_select_related = ["casa", "casa__municipio", "casa__municipio__uf"] search_fields = ( @@ -469,6 +478,11 @@ class SolicitacaoAdmin(AsciifyQParameter, CartExportMixin, admin.ModelAdmin): inlines = (ItemSolicitadoInline, AnexoSolicitacaoInline) autocomplete_fields = ("casa",) + def lookup_allowed(self, lookup, value): + return super().lookup_allowed(lookup, value) or ( + lookup == MicrorregiaoFilter.parameter_name + ) + def get_queryset(self, request): acts = Convenio.objects.filter( casa_legislativa=OuterRef("casa"),