Browse Source

App Servidores preparada para django 3

unstable/3.0
Sesostris Vieira 4 years ago
parent
commit
d0bd3822d4
  1. 1
      requirements/requirements.txt
  2. 70
      sigi/apps/servidores/admin.py
  3. 16
      sigi/apps/servidores/migrations/0001_initial.py
  4. 2
      sigi/apps/servidores/migrations/0006_auto_20210429_0822.py
  5. 32
      sigi/apps/servidores/models.py
  6. 2
      sigi/apps/servidores/templates/admin/servidores/servidor/change_form.html
  7. 14
      sigi/apps/servidores/templates/admin/servidores/servidor/change_list.html
  8. 2
      sigi/settings/base.py
  9. 2
      sigi/urls.py

1
requirements/requirements.txt

@ -2,3 +2,4 @@ ipython==7.24.1
Django==3.2.4
psycopg2==2.8.6
django-bootstrap5==2.0.1
Pillow==8.2.0

70
sigi/apps/servidores/admin.py

@ -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")

16
sigi/apps/servidores/migrations/0001_initial.py

@ -97,8 +97,8 @@ class Migration(migrations.Migration):
('apontamentos', models.TextField(null=True, verbose_name='apontamentos', blank=True)),
('email_pessoal', models.EmailField(max_length=75, null=True, verbose_name=b'email pessoal', blank=True)),
('ramal', models.CharField(max_length=25, null=True, blank=True)),
('servico', models.ForeignKey(blank=True, to='servidores.Servico', null=True)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, unique=True)),
('servico', models.ForeignKey(blank=True, to='servidores.Servico', null=True, on_delete=models.CASCADE)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, unique=True, on_delete=models.CASCADE)),
],
options={
'ordering': ('nome_completo',),
@ -112,7 +112,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('nome', models.CharField(max_length=250, null=True)),
('sigla', models.CharField(max_length=10, null=True)),
('responsavel', models.ForeignKey(related_name=b'diretor', to='servidores.Servidor', null=True)),
('responsavel', models.ForeignKey(related_name=b'diretor', to='servidores.Servidor', null=True, on_delete=models.CASCADE)),
],
options={
'ordering': ('nome',),
@ -122,31 +122,31 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='servico',
name='responsavel',
field=models.ForeignKey(related_name=b'chefe', to='servidores.Servidor', null=True),
field=models.ForeignKey(related_name=b'chefe', to='servidores.Servidor', null=True, on_delete=models.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='servico',
name='subsecretaria',
field=models.ForeignKey(to='servidores.Subsecretaria', null=True),
field=models.ForeignKey(to='servidores.Subsecretaria', null=True, on_delete=models.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='licenca',
name='servidor',
field=models.ForeignKey(to='servidores.Servidor'),
field=models.ForeignKey(to='servidores.Servidor', on_delete=models.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='funcao',
name='servidor',
field=models.ForeignKey(to='servidores.Servidor'),
field=models.ForeignKey(to='servidores.Servidor', on_delete=models.CASCADE),
preserve_default=True,
),
migrations.AddField(
model_name='ferias',
name='servidor',
field=models.ForeignKey(to='servidores.Servidor'),
field=models.ForeignKey(to='servidores.Servidor', on_delete=models.CASCADE),
preserve_default=True,
),
]

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

@ -15,7 +15,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='servidor',
name='user',
field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True),
field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE),
preserve_default=True,
),
]

32
sigi/apps/servidores/models.py

@ -1,19 +1,17 @@
# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.db import models
from django.db.models.signals import post_save
from django.utils.translation import ugettext as _
class Servico(models.Model):
nome = models.CharField(_(u'Setor'), max_length=250, null=True)
nome = models.CharField(_('setor'), max_length=250, null=True)
sigla = models.CharField(max_length=10, null=True)
subordinado = models.ForeignKey(
'self',
on_delete=models.SET_NULL,
null=True,
blank=True,
verbose_name=_(u"subordinado a")
verbose_name=_("subordinado a")
)
responsavel = models.ForeignKey(
'servidores.Servidor',
@ -25,11 +23,11 @@ class Servico(models.Model):
class Meta:
ordering = ('-subordinado__sigla', 'nome',)
verbose_name = _(u'serviço')
verbose_name_plural = _(u'serviços')
verbose_name = _('serviço')
verbose_name_plural = _('serviços')
def __unicode__(self):
return u"{sigla} - {nome}".format(sigla=self.sigla, nome=self.nome)
def __str__(self):
return "{sigla} - {nome}".format(sigla=self.sigla, nome=self.nome)
class Servidor(models.Model):
user = models.ForeignKey(
@ -38,9 +36,10 @@ class Servidor(models.Model):
null=True,
blank=True
)
nome_completo = models.CharField(max_length=128)
apelido = models.CharField(max_length=50, blank=True)
nome_completo = models.CharField(_('nome completo'), max_length=128)
apelido = models.CharField(_('apelido'), max_length=50, blank=True)
foto = models.ImageField(
_('foto'),
upload_to='fotos/servidores',
width_field='foto_largura',
height_field='foto_altura',
@ -52,20 +51,21 @@ class Servidor(models.Model):
Servico,
on_delete=models.SET_NULL,
blank=True,
null=True
null=True,
verbose_name=_('serviço')
)
externo = models.BooleanField(_(u"colaborador externo"), default=False)
externo = models.BooleanField(_("colaborador externo"), default=False)
orgao_origem = models.CharField(
_(u"órgão de origem, "),
_("órgão de origem, "),
max_length=100, blank=True
)
qualificacoes = models.TextField(_(u"qualificações"), blank=True)
qualificacoes = models.TextField(_("qualificações"), blank=True)
class Meta:
ordering = ('nome_completo',)
verbose_name_plural = 'servidores'
verbose_name_plural = _('servidores')
def __unicode__(self):
def __str__(self):
return self.nome_completo
def save(self, *args, **kwargs):

2
sigi/apps/servidores/templates/admin/servidores/servidor/change_form.html

@ -1,4 +1,4 @@
{% extends 'base_change_form.html' %}
{% extends 'admin/change_form.html' %}
{% load i18n %}
{% block form_top %}

14
sigi/apps/servidores/templates/admin/servidores/servidor/change_list.html

@ -1,14 +0,0 @@
{% extends 'admin/change_list.html' %}
{% load i18n reporting_tags %}
{% block object-tools-items %}
<li><a href="/servidores/servidores_por_cargo.pdf" class="historylink">
<span class="glyphicon glyphicon-list-alt"></span>
{% trans 'Relatório por cargo' %}
</a></li>
<li><a href="/servidores/servidores_por_funcao.pdf" class="historylink">
<span class="glyphicon glyphicon-list-alt"></span>
{% trans 'Relatório por função' %}
</a></li>
{{ block.super }}
{% endblock %}

2
sigi/settings/base.py

@ -26,7 +26,7 @@ INSTALLED_APPS = [
'sigi.apps.utils',
# 'sigi.apps.home',
'sigi.apps.contatos',
# 'sigi.apps.servidores',
'sigi.apps.servidores',
# 'sigi.apps.parlamentares',
# 'sigi.apps.casas',
# 'sigi.apps.convenios',

2
sigi/urls.py

@ -19,7 +19,7 @@ from django.views.static import serve
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('', admin.site.urls),
]
if settings.DEBUG:

Loading…
Cancel
Save