|
|
@ -1,34 +1,9 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
from django.contrib import admin |
|
|
|
from django.contrib.contenttypes import generic |
|
|
|
from django.contrib.admin.filters import RelatedOnlyFieldListFilter |
|
|
|
from django.utils.safestring import mark_safe |
|
|
|
from django.utils.translation import ugettext as _ |
|
|
|
|
|
|
|
from sigi.apps.contatos.models import Endereco, Telefone |
|
|
|
from sigi.apps.servidores.models import Servidor, Servico |
|
|
|
from sigi.apps.utils.admin_widgets import AdminImageWidget |
|
|
|
from sigi.apps.utils.base_admin import BaseModelAdmin |
|
|
|
from sigi.apps.utils.filters import AlphabeticFilter |
|
|
|
|
|
|
|
class ServidorFilter(AlphabeticFilter): |
|
|
|
title = _(u'Nome do Servidor') |
|
|
|
parameter_name = 'servidor__nome_completo' |
|
|
|
|
|
|
|
class ServicoFilter(admin.SimpleListFilter): |
|
|
|
title = _(u"Subordinados à") |
|
|
|
parameter_name = 'subordinado__id__exact' |
|
|
|
|
|
|
|
def lookups(self, request, model_admin): |
|
|
|
return ([('None', _(u"Nenhum"))] + |
|
|
|
[(s.id, s.nome) for s in Servico.objects.exclude(servico=None)]) |
|
|
|
|
|
|
|
def queryset(self, request, queryset): |
|
|
|
if self.value(): |
|
|
|
if self.value() == "None": |
|
|
|
queryset = queryset.filter(subordinado=None) |
|
|
|
else: |
|
|
|
queryset = queryset.filter(subordinado__id=self.value()) |
|
|
|
return queryset |
|
|
|
|
|
|
|
|
|
|
|
class ServicoInline(admin.TabularInline): |
|
|
|
model = Servico |
|
|
@ -39,7 +14,7 @@ class ServidorInline(admin.TabularInline): |
|
|
|
fields = ('imagem_foto', 'nome_completo', 'is_active', ) |
|
|
|
readonly_fields = ('imagem_foto', 'nome_completo', 'is_active', ) |
|
|
|
|
|
|
|
def has_add_permission(self, request): |
|
|
|
def has_add_permission(self, request, obj): |
|
|
|
return False |
|
|
|
|
|
|
|
def has_delete_permission(self, request, obj): |
|
|
@ -47,11 +22,12 @@ class ServidorInline(admin.TabularInline): |
|
|
|
|
|
|
|
def imagem_foto(sels, servidor): |
|
|
|
if servidor.foto: |
|
|
|
return u'<img src="{url}" style="height: 60px; width: 60px; border-radius: 50%;">'.format(url=servidor.foto.url) |
|
|
|
return mark_safe('<img src="{url}" style="height: 60px; width: 60px' |
|
|
|
'; border-radius: 50%;">'.format( |
|
|
|
url=servidor.foto.url)) |
|
|
|
else: |
|
|
|
return u"" |
|
|
|
imagem_foto.short_description = _(u"foto") |
|
|
|
imagem_foto.allow_tags = True |
|
|
|
return "" |
|
|
|
imagem_foto.short_description = _("foto") |
|
|
|
|
|
|
|
def is_active(self, servidor): |
|
|
|
if servidor.user: |
|
|
@ -60,18 +36,17 @@ class ServidorInline(admin.TabularInline): |
|
|
|
return False |
|
|
|
is_active.admin_order_field = 'user__is_active' |
|
|
|
is_active.boolean = True |
|
|
|
is_active.short_description = _(u'ativo') |
|
|
|
|
|
|
|
is_active.short_description = _('ativo') |
|
|
|
|
|
|
|
@admin.register(Servico) |
|
|
|
class ServicoAdmin(admin.ModelAdmin): |
|
|
|
list_display = ['sigla', 'nome', 'subordinado', 'responsavel'] |
|
|
|
list_filter = [ServicoFilter,] |
|
|
|
list_filter = [('subordinado', RelatedOnlyFieldListFilter),] |
|
|
|
search_fields = ['nome', 'sigla',] |
|
|
|
inlines = [ServicoInline, ServidorInline,] |
|
|
|
|
|
|
|
@admin.register(Servidor) |
|
|
|
class ServidorAdmin(BaseModelAdmin): |
|
|
|
class ServidorAdmin(admin.ModelAdmin): |
|
|
|
list_display = ('imagem_foto', 'nome_completo', 'is_active', 'servico', ) |
|
|
|
list_display_links = ('imagem_foto', 'nome_completo',) |
|
|
|
list_filter = ('user__is_active', 'externo', 'servico') |
|
|
@ -83,7 +58,7 @@ class ServidorAdmin(BaseModelAdmin): |
|
|
|
(None, { |
|
|
|
'fields': ('user', 'nome_completo', 'foto', 'servico',) |
|
|
|
}), |
|
|
|
(_(u"outros órgãos"), { |
|
|
|
(_("outros órgãos"), { |
|
|
|
'fields': ('externo', 'orgao_origem', 'qualificacoes'), |
|
|
|
}), |
|
|
|
) |
|
|
@ -92,16 +67,6 @@ class ServidorAdmin(BaseModelAdmin): |
|
|
|
return super(ServidorAdmin, self).lookup_allowed(lookup, value) or \ |
|
|
|
lookup in ['user__is_active__exact'] |
|
|
|
|
|
|
|
# def has_add_permission(self, request): |
|
|
|
# return False |
|
|
|
|
|
|
|
def formfield_for_dbfield(self, db_field, **kwargs): |
|
|
|
if db_field.name == 'foto': |
|
|
|
request = kwargs.pop("request", None) |
|
|
|
kwargs['widget'] = AdminImageWidget |
|
|
|
return db_field.formfield(**kwargs) |
|
|
|
return super(ServidorAdmin, self).formfield_for_dbfield(db_field, **kwargs) |
|
|
|
|
|
|
|
def is_active(self, servidor): |
|
|
|
if servidor.user: |
|
|
|
return servidor.user.is_active |
|
|
@ -109,12 +74,13 @@ class ServidorAdmin(BaseModelAdmin): |
|
|
|
return False |
|
|
|
is_active.admin_order_field = 'user__is_active' |
|
|
|
is_active.boolean = True |
|
|
|
is_active.short_description = _(u'ativo') |
|
|
|
is_active.short_description = _('ativo') |
|
|
|
|
|
|
|
def imagem_foto(sels, servidor): |
|
|
|
if servidor.foto: |
|
|
|
return u'<img src="{url}" style="height: 60px; width: 60px; border-radius: 50%;">'.format(url=servidor.foto.url) |
|
|
|
return mark_safe('<img src="{url}" style="height: 60px; ' |
|
|
|
'width: 60px; border-radius: 50%;">'.format( |
|
|
|
url=servidor.foto.url)) |
|
|
|
else: |
|
|
|
return u"" |
|
|
|
imagem_foto.short_description = _(u"foto") |
|
|
|
imagem_foto.allow_tags = True |
|
|
|
return "" |
|
|
|
imagem_foto.short_description = _("foto") |