diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index c8fdb5c..24361ff 100644 --- a/sigi/apps/casas/admin.py +++ b/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'' + else: + return ( + 'account_circle' + ) - 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"{obj.url}" -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, diff --git a/sigi/apps/casas/templates/admin/casas/orgao/tabular.html b/sigi/apps/casas/templates/admin/casas/orgao/tabular.html new file mode 100644 index 0000000..5fc4b3d --- /dev/null +++ b/sigi/apps/casas/templates/admin/casas/orgao/tabular.html @@ -0,0 +1,115 @@ +{% load i18n admin_urls static admin_modify %} +
+ +
diff --git a/sigi/apps/convenios/admin.py b/sigi/apps/convenios/admin.py index 9b69236..59852d8 100644 --- a/sigi/apps/convenios/admin.py +++ b/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, diff --git a/sigi/apps/ocorrencias/admin.py b/sigi/apps/ocorrencias/admin.py index e686d56..e3b229c 100644 --- a/sigi/apps/ocorrencias/admin.py +++ b/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) diff --git a/sigi/apps/parlamentares/admin.py b/sigi/apps/parlamentares/admin.py index b5dcd80..8f911f3 100644 --- a/sigi/apps/parlamentares/admin.py +++ b/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/" diff --git a/sigi/apps/servicos/admin.py b/sigi/apps/servicos/admin.py index 722bdd2..9347e1a 100644 --- a/sigi/apps/servicos/admin.py +++ b/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", ] diff --git a/sigi/apps/servicos/migrations/0020_servico_apps.py b/sigi/apps/servicos/migrations/0020_servico_apps.py new file mode 100644 index 0000000..6aa2133 --- /dev/null +++ b/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"), + ), + ] diff --git a/sigi/apps/servicos/models.py b/sigi/apps/servicos/models.py index 16beb99..7e5e5dc 100644 --- a/sigi/apps/servicos/models.py +++ b/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 ) diff --git a/sigi/apps/utils/mixins.py b/sigi/apps/utils/mixins.py index d4224fc..28dc632 100644 --- a/sigi/apps/utils/mixins.py +++ b/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