From c9d6a7d914bccea11e996988d8692daa52b63b22 Mon Sep 17 00:00:00 2001 From: Breno Teixeira Date: Mon, 11 Nov 2013 16:26:04 -0200 Subject: [PATCH] =?UTF-8?q?Cria=C3=A7=C3=A3o=20do=20filtro=20por=20letras?= =?UTF-8?q?=20do=20alfabeto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/convenios/admin.py | 2 +- sigi/apps/convenios/models.py | 2 -- sigi/apps/diagnosticos/admin.py | 2 +- sigi/apps/diagnosticos/models.py | 2 +- sigi/apps/financeiro/admin.py | 4 ++- sigi/apps/inventario/models.py | 2 -- sigi/apps/metas/admin.py | 6 +++-- sigi/apps/ocorrencias/admin.py | 2 +- sigi/apps/ocorrencias/models.py | 2 +- sigi/apps/parlamentares/admin.py | 42 ++++++++++++++++++++++++++++++- sigi/apps/parlamentares/models.py | 1 - sigi/apps/parlamentares/urls.py | 1 - sigi/apps/servicos/admin.py | 7 ++++-- sigi/apps/servicos/models.py | 2 +- sigi/apps/servidores/admin.py | 6 +++-- sigi/apps/servidores/models.py | 4 +-- 16 files changed, 64 insertions(+), 23 deletions(-) diff --git a/sigi/apps/convenios/admin.py b/sigi/apps/convenios/admin.py index 9d301fa..2b74c67 100644 --- a/sigi/apps/convenios/admin.py +++ b/sigi/apps/convenios/admin.py @@ -55,7 +55,7 @@ class ConvenioAdmin(admin.ModelAdmin): 'projeto', ) list_display_links = ('num_convenio','casa_legislativa',) - list_filter = ('projeto','casa_legislativa','conveniada', 'equipada') + list_filter = ('projeto', 'casa_legislativa__municipio__uf', 'casa_legislativa','conveniada', 'equipada') #date_hierarchy = 'data_adesao' ordering = ('casa_legislativa__tipo__sigla','casa_legislativa__municipio__uf','casa_legislativa') raw_id_fields = ('casa_legislativa',) diff --git a/sigi/apps/convenios/models.py b/sigi/apps/convenios/models.py index 94f223c..f814e0d 100644 --- a/sigi/apps/convenios/models.py +++ b/sigi/apps/convenios/models.py @@ -31,8 +31,6 @@ class Convenio(models.Model): ) # campo de busca em caixa baixa e sem acentos search_text = SearchField(field_names=['casa_legislativa']) - casa_legislativa.convenio_uf_filter = True - casa_legislativa.convenio_cl_tipo_filter = True projeto = models.ForeignKey('Projeto') # numero designado pelo Senado Federal para o convênio num_processo_sf = models.CharField( diff --git a/sigi/apps/diagnosticos/admin.py b/sigi/apps/diagnosticos/admin.py index 3025779..db2f10a 100644 --- a/sigi/apps/diagnosticos/admin.py +++ b/sigi/apps/diagnosticos/admin.py @@ -49,7 +49,7 @@ class DiagnosticoAdmin(BaseEntityAdmin): inlines = (EquipeInline, AnexosInline) search_fields = ('casa_legislativa__nome',) list_display = ('casa_legislativa','get_uf', 'data_visita_inicio', 'data_visita_fim', 'responsavel', 'publicado') - list_filter = ('publicado', 'casa_legislativa', 'data_publicacao', 'data_visita_inicio', 'data_visita_fim') + list_filter = ('publicado', 'casa_legislativa__municipio__uf__nome', 'casa_legislativa', 'data_publicacao', 'data_visita_inicio', 'data_visita_fim') raw_id_fields = ('casa_legislativa',) ordering = ('casa_legislativa',) diff --git a/sigi/apps/diagnosticos/models.py b/sigi/apps/diagnosticos/models.py index f394795..29603c9 100644 --- a/sigi/apps/diagnosticos/models.py +++ b/sigi/apps/diagnosticos/models.py @@ -18,7 +18,7 @@ class Diagnostico(BaseEntity): # campo de busca em caixa baixa e sem acento search_text = SearchField(field_names=['casa_legislativa']) - casa_legislativa.casa_uf_filter = True + # casa_legislativa.casa_uf_filter = True # casa_legislativa.casa_tipo_filter = True data_visita_inicio = models.DateField( u'data inicial da visita', diff --git a/sigi/apps/financeiro/admin.py b/sigi/apps/financeiro/admin.py index 05ae4b7..c9e25c4 100644 --- a/sigi/apps/financeiro/admin.py +++ b/sigi/apps/financeiro/admin.py @@ -6,4 +6,6 @@ class DesembolsoAdmin(admin.ModelAdmin): list_display = ('projeto', 'descricao', 'data', 'valor_reais', 'valor_dolar',) fields = ('projeto', 'descricao', 'data', 'valor_reais', 'valor_dolar', ) list_filter = ('projeto',) - date_hierarchy = 'data' \ No newline at end of file + date_hierarchy = 'data' + +admin.site.register(Desembolso, DesembolsoAdmin) \ No newline at end of file diff --git a/sigi/apps/inventario/models.py b/sigi/apps/inventario/models.py index 2cde2eb..e93dc54 100644 --- a/sigi/apps/inventario/models.py +++ b/sigi/apps/inventario/models.py @@ -29,7 +29,6 @@ class Fabricante(models.Model): class TipoEquipamento(models.Model): tipo = models.CharField(max_length=40) - tipo.alphabetic_filter = True class Meta: ordering = ('tipo',) @@ -45,7 +44,6 @@ class ModeloEquipamento(models.Model): verbose_name='tipo de equipamento' ) modelo = models.CharField(max_length=30) - modelo.alphabetic_filter = True class Meta: ordering = ('modelo',) diff --git a/sigi/apps/metas/admin.py b/sigi/apps/metas/admin.py index b422ea7..51fe864 100644 --- a/sigi/apps/metas/admin.py +++ b/sigi/apps/metas/admin.py @@ -11,7 +11,7 @@ class PlanoDiretorAdmin(admin.ModelAdmin): list_display = ('projeto', 'casa_legislativa', 'get_uf', 'status', 'data_entrega', 'data_implantacao',) fields = ('projeto', 'casa_legislativa', 'status', 'data_entrega', 'data_implantacao',) raw_id_fields = ('casa_legislativa',) - list_filter = ('projeto', 'status', 'casa_legislativa', ) + list_filter = ('projeto', 'status', 'casa_legislativa', 'casa_legislativa__municipio__uf__nome') def get_uf(self, obj): return obj.casa_legislativa.municipio.uf.nome @@ -43,4 +43,6 @@ class PlanoDiretorAdmin(admin.ModelAdmin): request.GET['data_entrega__lte'] = '%s-01' % value #Complete with 1st day of month request.GET._mutable=False - return super(PlanoDiretorAdmin, self).changelist_view(request, extra_context) \ No newline at end of file + return super(PlanoDiretorAdmin, self).changelist_view(request, extra_context) + +admin.site.register(PlanoDiretor, PlanoDiretorAdmin) \ No newline at end of file diff --git a/sigi/apps/ocorrencias/admin.py b/sigi/apps/ocorrencias/admin.py index 4140661..ee37784 100644 --- a/sigi/apps/ocorrencias/admin.py +++ b/sigi/apps/ocorrencias/admin.py @@ -60,7 +60,7 @@ class OcorrenciaChangeList(ChangeList): class OcorrenciaAdmin(admin.ModelAdmin): list_display = ('data_criacao', 'casa_legislativa', 'assunto', 'prioridade', 'status', 'data_modificacao', 'setor_responsavel',) - list_filter = ('assunto', 'status', 'prioridade', 'categoria', 'setor_responsavel', ) + list_filter = ('categoria__nome', 'assunto', 'status', 'prioridade', 'setor_responsavel__nome', ) search_fields = ('casa_legislativa__search_text', 'assunto', 'servidor_registro__nome', ) date_hierarchy = 'data_criacao' fields = ('casa_legislativa', 'categoria', 'tipo_contato', 'assunto', 'status', 'prioridade', 'descricao', 'servidor_registro', diff --git a/sigi/apps/ocorrencias/models.py b/sigi/apps/ocorrencias/models.py index cb33d1c..49b3f04 100644 --- a/sigi/apps/ocorrencias/models.py +++ b/sigi/apps/ocorrencias/models.py @@ -7,7 +7,7 @@ from sigi.apps.utils import SearchField class Categoria(models.Model): - nome= models.CharField(u"Nome", max_length=50) + nome= models.CharField(u"Nome Categoria", max_length=50) descricao = models.TextField(u'descrição', blank=True, null=True) setor_responsavel = models.ForeignKey('servidores.Servico', verbose_name=u"Setor responsável") diff --git a/sigi/apps/parlamentares/admin.py b/sigi/apps/parlamentares/admin.py index 9fe27e7..598f08b 100644 --- a/sigi/apps/parlamentares/admin.py +++ b/sigi/apps/parlamentares/admin.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import string + from django.contrib import admin from django.contrib.contenttypes import generic from django.http import HttpResponse, HttpResponseRedirect @@ -22,11 +24,48 @@ class PartidoAdmin(admin.ModelAdmin): search_fields = ('nome', 'sigla') +class AlphabeticFilter(admin.SimpleListFilter): + # Human-readable title which will be displayed in the + # right admin sidebar just above the filter options. + title = '' + + # Parameter for the filter that will be used in the URL query. + parameter_name = '' + + alphabetic = string.ascii_uppercase + + def lookups(self, request, model_admin): + """ + Returns a list of tuples. The first element in each + tuple is the coded value for the option that will + appear in the URL query. The second element is the + human-readable name for the option that will appear + in the right sidebar. + """ + + return ((letter, letter,) for letter in self.alphabetic) + + def queryset(self, request, queryset): + """ + Returns the filtered queryset based on the value + provided in the query string and retrievable via + `self.value()`. + """ + + qs = self.parameter_name + '__istartswith', self.value() + return queryset.filter(qs) + + +class ParlamentarNomeCompletoFilter(AlphabeticFilter): + title = 'Nome Completo do Parlamentar' + parameter_name = 'nome_completo' + + class ParlamentarAdmin(admin.ModelAdmin): inlines = (TelefonesInline, MandatosInline) list_display = ('nome_completo', 'nome_parlamentar', 'sexo') list_display_links = ('nome_completo', 'nome_parlamentar') - list_filter = ('nome_completo', 'nome_parlamentar') + list_filter = ('nome_parlamentar', ParlamentarNomeCompletoFilter) actions = ['adiciona_parlamentar',] fieldsets = ( (None, { @@ -71,6 +110,7 @@ class MandatoAdmin(admin.ModelAdmin): raw_id_fields = ('parlamentar', 'legislatura', 'partido') # radio_fields = {'suplencia': admin.VERTICAL} + admin.site.register(Partido, PartidoAdmin) admin.site.register(Parlamentar, ParlamentarAdmin) admin.site.register(Mandato, MandatoAdmin) diff --git a/sigi/apps/parlamentares/models.py b/sigi/apps/parlamentares/models.py index 3edcbc4..71206ea 100644 --- a/sigi/apps/parlamentares/models.py +++ b/sigi/apps/parlamentares/models.py @@ -20,7 +20,6 @@ class Parlamentar(models.Model): ('F', 'Feminino'), ) nome_completo = models.CharField(max_length=128) - nome_completo.alphabetic_filter = True nome_parlamentar = models.CharField(max_length=35, blank=True) foto = models.ImageField( upload_to='fotos/parlamentares', diff --git a/sigi/apps/parlamentares/urls.py b/sigi/apps/parlamentares/urls.py index a9ff3e2..ce518fc 100644 --- a/sigi/apps/parlamentares/urls.py +++ b/sigi/apps/parlamentares/urls.py @@ -1,7 +1,6 @@ # coding: utf-8 from django.conf.urls import patterns, url - urlpatterns = patterns('sigi.apps.parlamentares.views', # Reports labels parlamentares diff --git a/sigi/apps/servicos/admin.py b/sigi/apps/servicos/admin.py index 54b16e2..a01e96b 100644 --- a/sigi/apps/servicos/admin.py +++ b/sigi/apps/servicos/admin.py @@ -64,7 +64,7 @@ class ServicoAdmin(admin.ModelAdmin): 'fields': ('data_alteracao', 'data_desativacao', 'motivo_desativacao',) })) readonly_fields = ('casa_legislativa', 'data_ativacao', 'data_alteracao') - list_filter = ('tipo_servico', 'hospedagem_interlegis', 'data_ultimo_uso', 'casa_legislativa', ) + list_filter = ('tipo_servico', 'hospedagem_interlegis', 'data_ultimo_uso', 'casa_legislativa__municipio__uf', ) list_display_links = [] ordering = ('casa_legislativa__municipio__uf', 'casa_legislativa', 'tipo_servico',) inlines = (LogServicoInline,) @@ -178,7 +178,7 @@ class CasaAtendidaAdmin(admin.ModelAdmin): ,) readonly_fields = ('nome', 'logradouro', 'bairro', 'municipio', 'cep') inlines = (ContatosInline,) - list_filter = ('tipo', 'codigo_interlegis', 'municipio', ) + list_filter = ('tipo', 'servico__tipo_servico', 'municipio__uf__nome', ) search_fields = ('search_text','cnpj', 'bairro', 'logradouro', 'cep', 'municipio__nome', 'municipio__uf__nome', 'municipio__codigo_ibge', 'pagina_web', 'observacoes') @@ -213,3 +213,6 @@ class CasaAtendidaAdmin(admin.ModelAdmin): def has_delete_permission(self, request, obj=None): return False # Nunca deletar casas por aqui +admin.site.register(Servico, ServicoAdmin) +admin.site.register(TipoServico, TipoServicoAdmin) +admin.site.register(CasaAtendida, CasaAtendidaAdmin) \ No newline at end of file diff --git a/sigi/apps/servicos/models.py b/sigi/apps/servicos/models.py index 7ba71e9..eec8f6c 100644 --- a/sigi/apps/servicos/models.py +++ b/sigi/apps/servicos/models.py @@ -49,7 +49,7 @@ class Servico(models.Model): erro_atualizacao = models.CharField(u"Erro na atualização", blank=True, max_length=200, help_text=u"Erro ocorrido na última tentativa de atualizar a data de último acesso") - casa_legislativa.casa_uf_filter = True + # casa_legislativa.casa_uf_filter = True def atualiza_data_uso(self): def reset(erro=u"", comment=u""): diff --git a/sigi/apps/servidores/admin.py b/sigi/apps/servidores/admin.py index 362d436..911a0bc 100644 --- a/sigi/apps/servidores/admin.py +++ b/sigi/apps/servidores/admin.py @@ -3,7 +3,7 @@ from django.contrib import admin from django.contrib.contenttypes import generic from sigi.apps.utils.admin_widgets import AdminImageWidget -from sigi.apps.servidores.models import Servidor, Funcao, Licenca, Ferias +from sigi.apps.servidores.models import Servidor, Funcao, Licenca, Ferias, Servico, Subsecretaria from sigi.apps.contatos.models import Endereco, Telefone from sigi.apps.servidores.forms import FeriasForm, LicencaForm, FuncaoForm @@ -49,7 +49,7 @@ class ServidorAdmin(admin.ModelAdmin): is_active.short_description = 'ativo' list_display = ('nome_completo', 'is_active', 'foto', 'servico', ) - list_filter = ('user', 'sexo', 'servico',) + list_filter = ('user__is_active', 'sexo', 'servico',) search_fields = ('nome_completo', 'obs', 'apontamentos', 'user__email', 'user__first_name', 'user__last_name', 'user__username') @@ -85,3 +85,5 @@ admin.site.register(Servidor, ServidorAdmin) admin.site.register(Funcao, FuncaoAdmin) admin.site.register(Ferias, FeriasAdmin) admin.site.register(Licenca, LicencaAdmin) +admin.site.register(Servico) +admin.site.register(Subsecretaria) \ No newline at end of file diff --git a/sigi/apps/servidores/models.py b/sigi/apps/servidores/models.py index cf23f03..0cb8722 100644 --- a/sigi/apps/servidores/models.py +++ b/sigi/apps/servidores/models.py @@ -23,7 +23,7 @@ class Servico(models.Model): """ Modelo para representação dos Serviços de uma Subsecretaria """ - nome = models.CharField(max_length=250, null=True) + nome = models.CharField(u'Nome Serviço', max_length=250, null=True) sigla = models.CharField(max_length=10, null=True) subsecretaria = models.ForeignKey(Subsecretaria, null=True) # servidor responsavel por chefiar o serviço @@ -58,9 +58,7 @@ class Servidor(models.Model): # usuario responsavel pela autenticação do servidor no sistema user = models.ForeignKey(User, unique=True) - user.is_active__filter = True nome_completo = models.CharField(max_length=128) - nome_completo.alphabetic_filter = True apelido = models.CharField(max_length=50, blank=True) # caminho no sistema para arquivo com a imagem foto = models.ImageField(