Browse Source

Inlines de órgão readonly.

Prepara serviços para sincronizar DNS
pull/160/head
Sesostris Vieira 2 years ago
parent
commit
17b4753389
  1. 162
      sigi/apps/casas/admin.py
  2. 115
      sigi/apps/casas/templates/admin/casas/orgao/tabular.html
  3. 8
      sigi/apps/convenios/admin.py
  4. 14
      sigi/apps/ocorrencias/admin.py
  5. 4
      sigi/apps/parlamentares/admin.py
  6. 4
      sigi/apps/servicos/admin.py
  7. 18
      sigi/apps/servicos/migrations/0020_servico_apps.py
  8. 1
      sigi/apps/servicos/models.py
  9. 29
      sigi/apps/utils/mixins.py

162
sigi/apps/casas/admin.py

@ -22,7 +22,11 @@ from sigi.apps.servicos.models import Servico
from sigi.apps.servicos.filters import ServicoAtivoFilter
from sigi.apps.servidores.models import Servidor
from sigi.apps.utils import queryset_ascii
from sigi.apps.utils.mixins import CartExportReportMixin, LabeledResourse
from sigi.apps.utils.mixins import (
ReturnMixin,
CartExportReportMixin,
LabeledResourse,
)
class OrgaoExportResourse(LabeledResourse):
@ -78,57 +82,56 @@ class TelefonesInline(GenericTabularInline):
extra = 1
class ParlamentarInline(admin.StackedInline):
class ParlamentarInline(admin.TabularInline):
model = Parlamentar
template = "admin/casas/orgao/tabular.html"
fields = (
"foto",
"get_foto",
"nome_parlamentar",
"nome_completo",
"partido",
"presidente",
"data_nascimento",
"cpf",
"identidade",
"telefones",
"status_mandato",
"get_partido",
"email",
"redes_sociais",
"ult_alteracao",
"presidente",
)
autocomplete_fields = ("partido",)
readonly_fields = ("ult_alteracao",)
readonly_fields = fields
extra = 0
max_num = 0
show_change_link = True
can_delete = False
def has_add_permission(self, request, *args, **kwargs):
return False
@mark_safe
@admin.display(description=_("Foto"))
def get_foto(self, obj):
if obj.foto:
return f'<img class="circle" src="{obj.foto.url}" style="width: 58px; height: 58px;"/>'
else:
return (
'<i class="material-icons medium grey-text">account_circle</i>'
)
def has_delete_permission(self, request, *args, **kwargs):
return False
@admin.display(description=_("Partido"))
def get_partido(self, obj):
return obj.partido.sigla
class FuncionariosInline(admin.StackedInline):
class FuncionarioInline(admin.TabularInline):
model = Funcionario
template = "admin/casas/orgao/tabular.html"
fields = (
"nome",
"sexo",
"data_nascimento",
"nota",
"email",
"cargo",
"funcao",
"setor",
"tempo_de_servico",
"ult_alteracao",
"endereco",
"municipio",
"bairro",
"cep",
"redes_sociais",
"desativado",
"observacoes",
)
autocomplete_fields = ("municipio",)
readonly_fields = ("ult_alteracao",)
extra = 1
readonly_fields = fields
extra = 0
max_num = 0
show_change_link = True
can_delete = False
verbose_name_plural = _("Contatos da Casa")
def get_queryset(self, request):
@ -141,40 +144,28 @@ class FuncionariosInline(admin.StackedInline):
)
class ConveniosInline(admin.StackedInline):
class ConveniosInline(admin.TabularInline):
model = Convenio
template = "admin/casas/orgao/tabular.html"
fields = (
"num_processo_sf",
"link_sigad",
"status_convenio",
"num_convenio",
"projeto",
"observacao",
"data_retorno_assinatura",
"data_termino_vigencia",
"data_pub_diario",
"data_sigad",
"data_solicitacao",
"get_anexos",
)
readonly_fields = [
"link_sigad",
"status_convenio",
"get_anexos",
]
readonly_fields = fields
ordering = ("-data_retorno_assinatura",)
readonly_fields = fields
extra = 0
can_delete = False
max_num = 0
show_change_link = True
@admin.display(description=_("Anexos"))
def get_anexos(self, obj):
return mark_safe(
render_to_string(
"admin/casas/anexo_convenio_snippet.html",
context={"anexos": obj.anexo_set.all()},
)
)
can_delete = False
@admin.display(description=_("Status do convênio"))
def status_convenio(self, obj):
@ -198,25 +189,38 @@ class ConveniosInline(admin.StackedInline):
return mark_safe(obj.get_sigad_url(display_type="icone"))
class ServicoInline(admin.StackedInline):
class ServicoInline(admin.TabularInline):
model = Servico
template = "admin/casas/orgao/tabular.html"
fields = (
"tipo_servico",
"url",
"get_tipo_servico",
"get_url",
"hospedagem_interlegis",
"data_ativacao",
"data_alteracao",
"data_desativacao",
"motivo_desativacao",
"resultado_verificacao",
"data_ultimo_uso",
)
readonly_fields = ["data_alteracao"]
readonly_fields = fields
ordering = ("tipo_servico", "-data_alteracao")
extra = 0
max_num = 0
show_change_link = True
can_delete = False
@admin.display(description=_("Tipo de serviço"), ordering="tipo_servico")
def get_tipo_servico(self, obj):
return obj.tipo_servico.sigla
@mark_safe
@admin.display(description="Url do serviço", ordering="url")
def get_url(self, obj):
return f"<a href='{obj.url}' target='_blank'>{obj.url}</a>"
class OcorrenciaInline(admin.StackedInline):
class OcorrenciaInline(admin.TabularInline):
model = Ocorrencia
template = "admin/casas/orgao/tabular.html"
fields = (
"data_criacao",
"categoria",
@ -224,26 +228,26 @@ class OcorrenciaInline(admin.StackedInline):
"assunto",
"prioridade",
"status",
"descricao",
"resolucao",
"ticket",
"data_modificacao",
)
autocomplete_fields = ("categoria", "tipo_contato")
readonly_fields = (
"data_criacao",
"data_modificacao",
)
readonly_fields = fields
ordering = ("-data_modificacao",)
extra = 0
can_delete = False
max_num = 0
show_change_link = True
can_delete = False
def has_add_permission(self, request, obj):
if Servidor.objects.filter(user=request.user).exists():
return super().has_add_permission(request, obj)
return False
def has_change_permission(self, request, obj):
if Servidor.objects.filter(user=request.user).exists():
return super().has_change_permission(request, obj)
return False
@admin.register(TipoOrgao)
class TipoOrgaoAdmin(admin.ModelAdmin):
@ -252,6 +256,34 @@ class TipoOrgaoAdmin(admin.ModelAdmin):
search_fields = ("sigla", "nome")
@admin.register(Funcionario)
class FuncionarioAdmin(ReturnMixin, admin.ModelAdmin):
fieldsets = (
(None, {"fields": ("nome", "sexo", "data_nascimento")}),
(_("Documentos"), {"fields": ("cpf", "identidade")}),
(_("Contato"), {"fields": ("nota", "email", "redes_sociais")}),
(_("Endereço"), {"fields": ("endereco", "municipio", "bairro", "cep")}),
(
_("Vínculo"),
{
"fields": (
"casa_legislativa",
"cargo",
"funcao",
"setor",
"tempo_de_servico",
)
},
),
(
_("Validade"),
{"fields": ("ult_alteracao", "desativado", "observacoes")},
),
)
readonly_fields = ("ult_alteracao",)
autocomplete_fields = ("casa_legislativa", "municipio")
@admin.register(Orgao)
class OrgaoAdmin(CartExportReportMixin, admin.ModelAdmin):
form = OrgaoForm
@ -259,7 +291,7 @@ class OrgaoAdmin(CartExportReportMixin, admin.ModelAdmin):
inlines = (
TelefonesInline,
ParlamentarInline,
FuncionariosInline,
FuncionarioInline,
ConveniosInline,
ServicoInline,
OcorrenciaInline,

115
sigi/apps/casas/templates/admin/casas/orgao/tabular.html

@ -0,0 +1,115 @@
{% load i18n admin_urls static admin_modify %}
<div class="js-inline-admin-formset inline-group" id="{{ inline_admin_formset.formset.prefix }}-group"
data-inline-type="tabular"
data-inline-formset="{{ inline_admin_formset.inline_formset_data }}">
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
{{ inline_admin_formset.formset.management_form }}
<fieldset class="module {{ inline_admin_formset.classes }}">
<legend></legend>
<h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
{{ inline_admin_formset.formset.non_form_errors }}
<table aria-describedby="tabular inline">
<thead>
<tr>
<th scope="row"class="original"></th>
{% for field in inline_admin_formset.fields %}
{% if not field.widget.is_hidden %}
<th scope="row"class="column-{{ field.name }}{% if field.required %} required{% endif %}">{{ field.label|capfirst }}
{% if field.help_text %}
<i class="help help-tooltip material-icons small-icon" aria-hidden="true"
title="{{ field.help_text|striptags }}">help_outline</i>
{% endif %}
</th>
{% endif %}
{% endfor %}
{% if inline_admin_formset.formset.can_delete %}<th scope="row"class="center">{% trans "Delete?" %}</th>{% endif %}
</tr>
</thead>
<tbody>
{% for inline_admin_form in inline_admin_formset %}
{% if inline_admin_form.form.non_field_errors %}
<tr>
<td colspan="{{ inline_admin_form|cell_count }}">
{{ inline_admin_form.form.non_field_errors }}
</td>
</tr>
{% endif %}
<tr class="form-row {% cycle 'row1' 'row2' %}
{% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}
{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form{% endif %}"
title="{{ inline_admin_form.original|default_if_none:'' }}"
id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
<td class="original">
{% if inline_admin_form.original or inline_admin_form.show_url %}
<p class="inline-show-change-link">
{% if inline_admin_form.original %}
{% if inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %}
<a href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}?_return={% url opts|admin_urlname:'change' object_id|admin_urlquote %}{% if form_url %}{{ form_url }}{% endif %}">
<i class="material-icons" aria-hidden="true">
{% if inline_admin_formset.has_change_permission %}edit{% else %}remove_red_eye{% endif %}
</i>
</a>
{% endif %}
{% endif %}
{% if inline_admin_form.show_url %}
<a href="{{ inline_admin_form.absolute_url }}">{% trans "View on site" %}</a>
{% endif %}
</p>
{% endif %}
{% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
{% if inline_admin_form.fk_field %}{{ inline_admin_form.fk_field.field }}{% endif %}
{% spaceless %}
{% for fieldset in inline_admin_form %}
{% for line in fieldset %}
{% for field in line %}
{% if not field.is_readonly and field.field.is_hidden %}{{ field.field }}{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endspaceless %}
</td>
{% for fieldset in inline_admin_form %}
{% for line in fieldset %}
{% for field in line %}
{% if field.is_readonly or not field.field.is_hidden %}
<td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
{% if field.is_readonly %}
<p>{{ field.contents }}</p>
{% else %}
{{ field.field.errors.as_ul }}
{{ field.field }}
<span></span>
{% endif %}
</td>
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% if inline_admin_formset.formset.can_delete %}
<td class="delete">
{% if inline_admin_form.original %}
{{ inline_admin_form.deletion_field.field }}
{% endif %}
<i class="material-icons delete-inline-row" aria-hidden="true">delete_forever</i>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% if inline_admin_formset.has_add_permission %}
<div>
<a href="{% url inline_admin_formset.opts.opts|admin_urlname:'add' %}?{{ inline_admin_formset.formset.fk.name }}={{ object_id|admin_urlquote }}&_return={% url opts|admin_urlname:'change' object_id|admin_urlquote %}{% if form_url %}{{ form_url }}{% endif %}" class="add-inline-link">
<i class="material-icons" aria-hidden="true">add</i>
<span>
{% blocktrans with verbose_name=inline_admin_formset.opts.verbose_name|capfirst %}
Adicionar outro(a) {{ verbose_name }}
{% endblocktrans %}
</span>
</a>
</div>
{% endif %}
</fieldset>
</div>
</div>

8
sigi/apps/convenios/admin.py

@ -20,7 +20,11 @@ from sigi.apps.convenios.models import (
from sigi.apps.utils import queryset_ascii
from sigi.apps.servidores.models import Servidor
from sigi.apps.casas.admin import ConveniosInline, GerentesInterlegisFilter
from sigi.apps.utils.mixins import CartExportReportMixin, LabeledResourse
from sigi.apps.utils.mixins import (
ReturnMixin,
CartExportReportMixin,
LabeledResourse,
)
from sigi.apps.utils.filters import DateRangeFilter
@ -102,7 +106,7 @@ class ProjetoAdmin(admin.ModelAdmin):
@admin.register(Convenio)
class ConvenioAdmin(CartExportReportMixin, admin.ModelAdmin):
class ConvenioAdmin(ReturnMixin, CartExportReportMixin, admin.ModelAdmin):
fieldsets = (
(
None,

14
sigi/apps/ocorrencias/admin.py

@ -12,7 +12,7 @@ from sigi.apps.ocorrencias.models import (
TipoContato,
)
from sigi.apps.servidores.models import Servidor
from sigi.apps.utils.base_admin import BaseModelAdmin
from sigi.apps.utils.mixins import ReturnMixin
from sigi.apps.casas.admin import GerentesInterlegisFilter
@ -68,7 +68,7 @@ class TipoContatoAdmin(admin.ModelAdmin):
@admin.register(Ocorrencia)
class OcorrenciaAdmin(admin.ModelAdmin):
class OcorrenciaAdmin(ReturnMixin, admin.ModelAdmin):
list_display = (
"data_criacao",
"casa_legislativa",
@ -143,6 +143,16 @@ class OcorrenciaAdmin(admin.ModelAdmin):
return super().get_fieldsets(request, obj)
def has_add_permission(self, request):
if Servidor.objects.filter(user=request.user).exists():
return super().has_add_permission(request)
return False
def has_change_permission(self, request, *args, **kwargs):
if Servidor.objects.filter(user=request.user).exists():
return super().has_change_permission(request, *args, **kwargs)
return False
def save_model(self, request, obj, form, change):
if not change:
obj.servidor_registro = Servidor.objects.get(user=request.user)

4
sigi/apps/parlamentares/admin.py

@ -2,6 +2,7 @@ import json
import tablib
from django.db.models import Q
from django.contrib import admin
from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render
from django.urls import path, reverse
from django.utils import timezone
@ -16,6 +17,7 @@ from sigi.apps.parlamentares.models import Partido, Parlamentar, Senador
from sigi.apps.parlamentares.forms import ImportForm
from sigi.apps.utils.filters import AlphabeticFilter
from sigi.apps.utils.mixins import (
ReturnMixin,
ImportCartExportMixin,
CartExportMixin,
LabeledResourse,
@ -144,7 +146,7 @@ class PartidoAdmin(ImportCartExportMixin, admin.ModelAdmin):
@admin.register(Parlamentar)
class ParlamentarAdmin(CartExportMixin, admin.ModelAdmin):
class ParlamentarAdmin(ReturnMixin, CartExportMixin, admin.ModelAdmin):
resource_class = ParlamentarResource
change_list_template = (
"admin/parlamentares/parlamentar/cart/"

4
sigi/apps/servicos/admin.py

@ -9,7 +9,7 @@ from sigi.apps.casas.admin import GerentesInterlegisFilter
from sigi.apps.servicos.models import Servico, LogServico, TipoServico
from sigi.apps.servicos.filters import ServicoAtivoFilter, DataUtimoUsoFilter
from sigi.apps.utils.filters import DateRangeFilter
from sigi.apps.utils.mixins import CartExportMixin, LabeledResourse
from sigi.apps.utils.mixins import ReturnMixin, CartExportMixin, LabeledResourse
class ServicoExportResourse(LabeledResourse):
@ -64,7 +64,7 @@ class TipoServicoAdmin(admin.ModelAdmin):
@admin.register(Servico)
class ServicoAdmin(CartExportMixin, admin.ModelAdmin):
class ServicoAdmin(ReturnMixin, CartExportMixin, admin.ModelAdmin):
actions = [
"calcular_data_uso",
]

18
sigi/apps/servicos/migrations/0020_servico_apps.py

@ -0,0 +1,18 @@
# Generated by Django 4.1.2 on 2022-11-08 19:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("servicos", "0019_ajusta_dominios"),
]
operations = [
migrations.AddField(
model_name="servico",
name="apps",
field=models.TextField(blank=True, verbose_name="apps instaladas no DNS"),
),
]

1
sigi/apps/servicos/models.py

@ -80,6 +80,7 @@ class Servico(models.Model):
instancia = models.CharField(
_("nome da instância"), max_length=100, blank=True
)
apps = models.TextField(_("apps instaladas no DNS"), blank=True)
data_ativacao = models.DateField(
_("Data de ativação"), default=timezone.localdate
)

29
sigi/apps/utils/mixins.py

@ -294,3 +294,32 @@ class CartExportReportMixin(CartExportMixin):
report_view = getattr(self, name)
return report_view(request)
class ReturnMixin:
_return_path = None
def changeform_view(
self, request, object_id=None, form_url="", extra_context=None
):
if "_return" in request.GET:
self._return_path = request.GET.get("_return")
return super().changeform_view(
request, object_id, form_url, extra_context
)
def response_post_save_add(self, request, obj):
if self._return_path:
return HttpResponseRedirect(self._return_path)
return super().response_post_save_add(request, obj)
def response_post_save_change(self, request, obj):
if self._return_path:
return HttpResponseRedirect(self._return_path)
return super().response_post_save_change(request, obj)
def response_delete(self, request, obj_display, obj_id):
response = super().response_delete(request, obj_display, obj_id)
if self._return_path:
return HttpResponseRedirect(self._return_path)
return response

Loading…
Cancel
Save