From 26a3bc02be21c7d0062eae9896c1f6f13de9649f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Fri, 6 May 2022 09:58:10 -0300 Subject: [PATCH] =?UTF-8?q?Usar=20membro=20da=20equipe=20na=20linha=20de?= =?UTF-8?q?=20assinatura=20da=20declara=C3=A7=C3=A3o=20de=20visita?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0021_equipe_assina_oficio.py | 18 +++ sigi/apps/eventos/models.py | 3 + .../admin/eventos/evento/change_form.html | 4 +- .../templates/eventos/declaracao_pdf.html | 5 + sigi/apps/eventos/views.py | 117 ++++++++++-------- sigi/apps/servidores/admin.py | 6 + .../migrations/0009_servidor_cargo.py | 18 +++ sigi/apps/servidores/models.py | 1 + 8 files changed, 120 insertions(+), 52 deletions(-) create mode 100644 sigi/apps/eventos/migrations/0021_equipe_assina_oficio.py create mode 100644 sigi/apps/servidores/migrations/0009_servidor_cargo.py diff --git a/sigi/apps/eventos/migrations/0021_equipe_assina_oficio.py b/sigi/apps/eventos/migrations/0021_equipe_assina_oficio.py new file mode 100644 index 0000000..580a2e4 --- /dev/null +++ b/sigi/apps/eventos/migrations/0021_equipe_assina_oficio.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.4 on 2022-05-06 12:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('eventos', '0020_anexo_convite'), + ] + + operations = [ + migrations.AddField( + model_name='equipe', + name='assina_oficio', + field=models.BooleanField(default=False, verbose_name='Assina ofício de comparecimento'), + ), + ] diff --git a/sigi/apps/eventos/models.py b/sigi/apps/eventos/models.py index 23cacee..cbc8a39 100644 --- a/sigi/apps/eventos/models.py +++ b/sigi/apps/eventos/models.py @@ -166,6 +166,9 @@ class Equipe(models.Model): funcao = models.ForeignKey( Funcao, on_delete=models.PROTECT, verbose_name=_("Função na equipe") ) + assina_oficio = models.BooleanField( + _("Assina ofício de comparecimento"), default=False + ) observacoes = models.TextField(_("Observações"), blank=True) class Meta: diff --git a/sigi/apps/eventos/templates/admin/eventos/evento/change_form.html b/sigi/apps/eventos/templates/admin/eventos/evento/change_form.html index b56ae80..5eb2d0b 100644 --- a/sigi/apps/eventos/templates/admin/eventos/evento/change_form.html +++ b/sigi/apps/eventos/templates/admin/eventos/evento/change_form.html @@ -2,11 +2,11 @@ {% load i18n %} {% block object-tools-items %} -
+
  • {% trans "Declaração" %} -
  • + {{ block.super }} {% endblock %} diff --git a/sigi/apps/eventos/templates/eventos/declaracao_pdf.html b/sigi/apps/eventos/templates/eventos/declaracao_pdf.html index 484ca7f..1ebf96e 100644 --- a/sigi/apps/eventos/templates/eventos/declaracao_pdf.html +++ b/sigi/apps/eventos/templates/eventos/declaracao_pdf.html @@ -1,6 +1,11 @@ {% extends 'pdf/base_report.html' %} {% load i18n %} +{% block page-footer-settings %} + {{ block.super }} + @bottom-right { content: ""; } +{% endblock %} + {% block page_size %}{{ pagesize }}{% endblock page_size %} {% block page_margin %}4cm {{ pagemargin }}cm {{ pagemargin }}cm 2cm{% endblock page_margin %} diff --git a/sigi/apps/eventos/views.py b/sigi/apps/eventos/views.py index 422a87e..1e87692 100644 --- a/sigi/apps/eventos/views.py +++ b/sigi/apps/eventos/views.py @@ -58,6 +58,65 @@ def calendario(request): return render(request, "eventos/calendario.html", context) +@login_required +def declaracao(request, id): + if request.method == "POST": + form = SelecionaModeloForm(request.POST) + if form.is_valid(): + evento = get_object_or_404(Evento, id=id) + modelo = form.cleaned_data["modelo"] + membro = ( + evento.equipe_set.filter(assina_oficio=True).first() + or evento.equipe_set.first() + ) + if membro: + servidor = membro.membro + else: + servidor = None + template_string = ( + """ + {% extends "eventos/declaracao_pdf.html" %} + {% block text_body %}""" + + modelo.texto + + """ + {% endblock %} + """ + ) + context = Context( + { + "pagesize": modelo.formato, + "pagemargin": modelo.margem, + "evento": evento, + "servidor": servidor, + "data": datetime.date.today(), + } + ) + string = Template(template_string).render(context) + # return HttpResponse(string) + response = HttpResponse( + headers={ + "Content-Type": "application/pdf", + "Content-Disposition": 'attachment; filename="declaração.pdf"', + } + ) + pdf = HTML( + string=string, + url_fetcher=django_url_fetcher, + encoding="utf-8", + base_url=request.build_absolute_uri("/"), + ) + pdf.write_pdf(target=response) + return response + else: + form = SelecionaModeloForm() + + context = site.each_context(request) + context["form"] = form + context["evento_id"] = id + + return render(request, "eventos/seleciona_modelo.html", context) + + def evento(request, id): context = site.each_context(request) evento = get_object_or_404(Evento, id=id) @@ -167,6 +226,13 @@ def convida_casa(request, evento_id, casa_id): query_str += f"anexo_id={oficio.id}&" if projeto.modelo_minuta: doc = Document(projeto.modelo_minuta.path) + if casa.tipo.sigla == "CM": + ente = ( + f"Município de {casa.municipio.nome}, " + f"{casa.municipio.uf.sigla}" + ) + else: + ente = f"Estado de {casa.municipio.uf.nome}" doc_context = Context( { "evento": evento, @@ -174,6 +240,7 @@ def convida_casa(request, evento_id, casa_id): "presidente": presidente, "contato": contato, "data": datetime.date.today(), + "ente": ente, "doravante": casa.tipo.nome.split(" ")[0], } ) @@ -621,53 +688,3 @@ def gerar_anexo(casa, presidente, contato, path, modelo, nome, texto): # writer.writerow(reg) # return response - - -@login_required -def declaracao(request, id): - if request.method == "POST": - form = SelecionaModeloForm(request.POST) - if form.is_valid(): - evento = get_object_or_404(Evento, id=id) - modelo = form.cleaned_data["modelo"] - template_string = ( - """ - {% extends "eventos/declaracao_pdf.html" %} - {% block text_body %}""" - + modelo.texto - + """ - {% endblock %} - """ - ) - context = Context( - { - "pagesize": modelo.formato, - "pagemargin": modelo.margem, - "evento": evento, - "data": datetime.date.today(), - } - ) - string = Template(template_string).render(context) - # return HttpResponse(string) - response = HttpResponse( - headers={ - "Content-Type": "application/pdf", - "Content-Disposition": 'attachment; filename="declaração.pdf"', - } - ) - pdf = HTML( - string=string, - url_fetcher=django_url_fetcher, - encoding="utf-8", - base_url=request.build_absolute_uri("/"), - ) - pdf.write_pdf(target=response) - return response - else: - form = SelecionaModeloForm() - - context = site.each_context(request) - context["form"] = form - context["evento_id"] = id - - return render(request, "eventos/seleciona_modelo.html", context) diff --git a/sigi/apps/servidores/admin.py b/sigi/apps/servidores/admin.py index b18dd00..45b9564 100644 --- a/sigi/apps/servidores/admin.py +++ b/sigi/apps/servidores/admin.py @@ -84,8 +84,10 @@ class ServidorAdmin(admin.ModelAdmin): list_display = ( "imagem_foto", "nome_completo", + "apelido", "is_active", "servico", + "cargo", ) list_display_links = ( "imagem_foto", @@ -98,6 +100,8 @@ class ServidorAdmin(admin.ModelAdmin): ) search_fields = ( "nome_completo", + "apelido", + "cargo", "user__email", "user__first_name", "user__last_name", @@ -113,8 +117,10 @@ class ServidorAdmin(admin.ModelAdmin): "fields": ( "user", "nome_completo", + "apelido", "foto", "servico", + "cargo", ) }, ), diff --git a/sigi/apps/servidores/migrations/0009_servidor_cargo.py b/sigi/apps/servidores/migrations/0009_servidor_cargo.py new file mode 100644 index 0000000..b200aed --- /dev/null +++ b/sigi/apps/servidores/migrations/0009_servidor_cargo.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.4 on 2022-05-06 12:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('servidores', '0008_alter_servico_id_alter_servidor_foto_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='servidor', + name='cargo', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/sigi/apps/servidores/models.py b/sigi/apps/servidores/models.py index 8c40c46..e5f32f7 100644 --- a/sigi/apps/servidores/models.py +++ b/sigi/apps/servidores/models.py @@ -51,6 +51,7 @@ class Servidor(models.Model): servico = models.ForeignKey( Servico, on_delete=models.SET_NULL, blank=True, null=True ) + cargo = models.CharField(max_length=100, blank=True) externo = models.BooleanField(_("colaborador externo"), default=False) orgao_origem = models.CharField( _("órgão de origem, "), max_length=100, blank=True