Browse Source

Fix #55

pull/66/head
Sesostris Vieira 4 years ago
parent
commit
5d90feb6b0
  1. 6
      sigi/apps/home/templatetags/menu_conf.yaml
  2. 18
      sigi/apps/servidores/admin.py
  3. 21
      sigi/apps/servidores/migrations/0006_auto_20210429_0822.py
  4. 12
      sigi/apps/servidores/models.py

6
sigi/apps/home/templatetags/menu_conf.yaml

@ -49,6 +49,12 @@ main_menu:
url: eventos/calendario
- title: Alocação de equipe
url: eventos/alocacaoequipe/
- title: Servidores
children:
- title: Serviços (unidades do ILB)
url: servidores/servico/
- title: Servidores e colaboradores
url: servidores/servidor/
- title: Tabelas auxiliares
children:
- title: Tipos de órgãos

18
sigi/apps/servidores/admin.py

@ -43,7 +43,8 @@ class ServicoAdmin(admin.ModelAdmin):
@admin.register(Servidor)
class ServidorAdmin(BaseModelAdmin):
list_display = ('foto', 'nome_completo', 'is_active', 'servico', )
list_display = ('imagem_foto', 'nome_completo', 'is_active', 'servico', )
list_display_links = ('imagem_foto', 'nome_completo',)
list_filter = ('user__is_active', 'servico',)
search_fields = ('nome_completo', 'user__email', 'user__first_name',
'user__last_name', 'user__username', 'servico__nome',
@ -55,8 +56,8 @@ 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 has_add_permission(self, request):
# return False
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'foto':
@ -66,7 +67,18 @@ class ServidorAdmin(BaseModelAdmin):
return super(ServidorAdmin, self).formfield_for_dbfield(db_field, **kwargs)
def is_active(self, servidor):
if servidor.user:
return servidor.user.is_active
else:
return False
is_active.admin_order_field = 'user__is_active'
is_active.boolean = True
is_active.short_description = _(u'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)
else:
return u""
imagem_foto.short_description = _(u"foto")
imagem_foto.allow_tags = True

21
sigi/apps/servidores/migrations/0006_auto_20210429_0822.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('servidores', '0005_auto_20210423_0904'),
]
operations = [
migrations.AlterField(
model_name='servidor',
name='user',
field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True),
preserve_default=True,
),
]

12
sigi/apps/servidores/models.py

@ -32,7 +32,12 @@ class Servico(models.Model):
return u"{sigla} - {nome}".format(sigla=self.sigla, nome=self.nome)
class Servidor(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, unique=True)
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
null=True,
blank=True
)
nome_completo = models.CharField(max_length=128)
apelido = models.CharField(max_length=50, blank=True)
foto = models.ImageField(
@ -57,6 +62,11 @@ class Servidor(models.Model):
def __unicode__(self):
return self.nome_completo
def save(self, *args, **kwargs):
if self.user is not None:
Servidor.objects.filter(user=self.user).update(user=None)
return super(Servidor, self).save(*args, **kwargs)
# Soluçao alternativa para extender o usuário do django
# Acessa do servidor de um objeto user criando um profile
# baseado nos dados do LDAP

Loading…
Cancel
Save