From b6b41e3d10c0c0c2f2a6419ace5bbf3b9e888333 Mon Sep 17 00:00:00 2001 From: Lude Ribeiro Date: Mon, 13 Dec 2021 10:39:56 -0300 Subject: [PATCH] Fix #116 --- sigi/apps/casas/admin.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index a5eb2f7..3685f93 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -374,6 +374,23 @@ class ServicoFilter(admin.SimpleListFilter): return queryset.distinct('municipio__uf__nome', 'nome') +class ServicoAtivoFilter(admin.SimpleListFilter): + title = _(u"Serviço ativo") + parameter_name = 'ativo' + + def lookups(self, request, model_admin): + return ( + ('ativo', _(u"Ativo")), + ('desativado', _(u"Desativado")), + ) + + def queryset(self, request, queryset): + if self.value() is not None: + if self.value() == 'ativo': + queryset = queryset.filter(servico__data_desativacao__isnull=True) + else: + queryset = queryset.filter(servico__data_desativacao__isnull=False) + return queryset @admin.register(Orgao) class OrgaoAdmin(ImageCroppingMixin, BaseModelAdmin): form = OrgaoForm @@ -384,7 +401,7 @@ class OrgaoAdmin(ImageCroppingMixin, BaseModelAdmin): 'get_servicos') list_display_links = ('sigla', 'nome',) list_filter = ('tipo', ('gerentes_interlegis', GerentesInterlegisFilter), - 'municipio__uf__nome', ConvenioFilter, ExcluirConvenioFilter, ServicoFilter, + 'municipio__uf__nome', ConvenioFilter, ServicoAtivoFilter, ExcluirConvenioFilter, ServicoFilter, 'inclusao_digital',) ordering = ('municipio__uf__nome', 'nome') queryset = queryset_ascii