From dcebe1ca9531d17c820781e5fb0b65fc442cbe1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 10 Feb 2022 11:34:36 -0300 Subject: [PATCH] =?UTF-8?q?App=20servi=C3=A7os=20com=20exporta=C3=A7=C3=A3?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/servicos/admin.py | 30 ++++++++++++++--- .../servicos/casaatendida/change_list.html | 23 ------------- .../templates/servico/change_list.html | 33 ------------------- 3 files changed, 26 insertions(+), 60 deletions(-) delete mode 100644 sigi/apps/servicos/templates/admin/servicos/casaatendida/change_list.html delete mode 100644 sigi/apps/servicos/templates/servico/change_list.html diff --git a/sigi/apps/servicos/admin.py b/sigi/apps/servicos/admin.py index 812726c..27fe9cb 100644 --- a/sigi/apps/servicos/admin.py +++ b/sigi/apps/servicos/admin.py @@ -1,4 +1,5 @@ from datetime import date, timedelta +import resource from django.contrib import admin from django.urls import reverse from django.utils.encoding import force_str @@ -6,11 +7,33 @@ from django.utils.safestring import mark_safe from django.forms.models import ModelForm from django.http import Http404, HttpResponseRedirect from django.utils.translation import gettext as _ - +from import_export.fields import Field from sigi.apps.casas.admin import FuncionariosInline, GerentesInterlegisFilter from sigi.apps.casas.models import Orgao from sigi.apps.servicos.models import (Servico, LogServico, CasaAtendida, TipoServico) +from sigi.apps.utils.mixins import CartExportMixin, LabeledResourse + +class ServicoExportResourse(LabeledResourse): + telefone_casa = Field(column_name='Casa Legislativa/telefone') + hospedagem_interlegis = Field(column_name='hospedagem no interlegis') + class Meta: + model = Servico + fields = ('casa_legislativa__nome', 'casa_legislativa__municipio__nome', + 'casa_legislativa__municipio__uf__sigla', + 'casa_legislativa__email', 'telefone_casa', + 'contato_tecnico__nome', 'contato_tecnico__email', + 'contato_tecnico__nota', 'tipo_servico__nome', 'url', + 'hospedagem_interlegis', 'data_ativacao', 'data_desativacao', + 'motivo_desativacao', 'data_ultimo_uso', 'erro_atualizacao') + export_order = fields + def dehydrate_telefone_casa(self, servico): + return servico.casa_legislativa.telefone + def dehydrate_hospedagem_interlegis(self, servico): + if servico.hospedagem_interlegis: + return _("Sim") + else: + return _("Não") class LogServicoInline(admin.StackedInline): @@ -110,8 +133,7 @@ class ServicoAtivoFilter(admin.SimpleListFilter): return queryset @admin.register(Servico) -class ServicoAdmin(admin.ModelAdmin): - change_list_template = "servico/change_list.html" +class ServicoAdmin(CartExportMixin, admin.ModelAdmin): form = ServicoFormAdmin actions = ['calcular_data_uso', ] list_display = ('casa_legislativa', 'get_codigo_interlegis', 'get_uf', @@ -142,11 +164,11 @@ class ServicoAdmin(admin.ModelAdmin): 'casa_legislativa__municipio__uf', ) list_display_links = [] - actions = ['adicionar_servicos'] ordering = ('casa_legislativa__municipio__uf', 'casa_legislativa', 'tipo_servico',) inlines = (LogServicoInline,) search_fields = ('casa_legislativa__search_text',) + resource_class = ServicoExportResourse def get_codigo_interlegis(self, obj): return obj.casa_legislativa.codigo_interlegis diff --git a/sigi/apps/servicos/templates/admin/servicos/casaatendida/change_list.html b/sigi/apps/servicos/templates/admin/servicos/casaatendida/change_list.html deleted file mode 100644 index 104fd94..0000000 --- a/sigi/apps/servicos/templates/admin/servicos/casaatendida/change_list.html +++ /dev/null @@ -1,23 +0,0 @@ -{% extends "admin/change_list.html" %} -{% load admin_list i18n admin_urls %} - -{% block extrahead %} -{{ block.super }} - -{% endblock %} - -{% block object-tools-items %} -
  • - - {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %} -
  • - {{ block.super }} -{% endblock %} diff --git a/sigi/apps/servicos/templates/servico/change_list.html b/sigi/apps/servicos/templates/servico/change_list.html deleted file mode 100644 index cc44655..0000000 --- a/sigi/apps/servicos/templates/servico/change_list.html +++ /dev/null @@ -1,33 +0,0 @@ -{% extends "change_list_with_cart.html" %} -{% load i18n %} - - -{% block extra_search %} - -{% endblock %} \ No newline at end of file