From 5d90feb6b02f136e0a95c75f96377c6fd308f7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 29 Apr 2021 11:25:31 -0300 Subject: [PATCH] Fix #55 --- sigi/apps/home/templatetags/menu_conf.yaml | 6 +++++ sigi/apps/servidores/admin.py | 22 ++++++++++++++----- .../migrations/0006_auto_20210429_0822.py | 21 ++++++++++++++++++ sigi/apps/servidores/models.py | 12 +++++++++- 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 sigi/apps/servidores/migrations/0006_auto_20210429_0822.py diff --git a/sigi/apps/home/templatetags/menu_conf.yaml b/sigi/apps/home/templatetags/menu_conf.yaml index 7f0d05c..271306a 100644 --- a/sigi/apps/home/templatetags/menu_conf.yaml +++ b/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 diff --git a/sigi/apps/servidores/admin.py b/sigi/apps/servidores/admin.py index 5e64ced..dcd9ece 100644 --- a/sigi/apps/servidores/admin.py +++ b/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): - return servidor.user.is_active + 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') \ No newline at end of file + is_active.short_description = _(u'ativo') + + def imagem_foto(sels, servidor): + if servidor.foto: + return u''.format(url=servidor.foto.url) + else: + return u"" + imagem_foto.short_description = _(u"foto") + imagem_foto.allow_tags = True \ No newline at end of file diff --git a/sigi/apps/servidores/migrations/0006_auto_20210429_0822.py b/sigi/apps/servidores/migrations/0006_auto_20210429_0822.py new file mode 100644 index 0000000..72737ed --- /dev/null +++ b/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, + ), + ] diff --git a/sigi/apps/servidores/models.py b/sigi/apps/servidores/models.py index 48c7128..97f518d 100644 --- a/sigi/apps/servidores/models.py +++ b/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