diff --git a/sigi/apps/convenios/jobs/daily/importa_gescon.py b/sigi/apps/convenios/jobs/daily/importa_gescon.py index cc79e72..7ef7691 100644 --- a/sigi/apps/convenios/jobs/daily/importa_gescon.py +++ b/sigi/apps/convenios/jobs/daily/importa_gescon.py @@ -1,6 +1,9 @@ +import datetime +import docutils.core +from django.core.mail import mail_admins +from django.utils.translation import gettext as _ from django_extensions.management.jobs import DailyJob from sigi.apps.convenios.models import Gescon -import datetime class Job(DailyJob): @@ -11,5 +14,23 @@ class Job(DailyJob): print(f"Import gescon data started at {now:%Y-%m-%d %H:%M:%S}") gescon = Gescon.load() gescon.importa_contratos() + self.report(gescon, now) now = datetime.datetime.now() print(f"Import gescon data finished at {now:%Y-%m-%d %H:%M:%S}") + + def report(self, gescon, now): + rst = gescon.ultima_importacao + html = docutils.core.publish_string( + rst, + writer_name="html5", + settings_overrides={ + "input_encoding": "unicode", + "output_encoding": "unicode", + }, + ) + mail_admins( + subject=_(f"Importação do GESCON em {now:%d/%m/%Y às %Hh%M}"), + message=rst, + html_message=html, + fail_silently=True, + ) diff --git a/sigi/apps/convenios/migrations/0032_gescon_palavras_excluir.py b/sigi/apps/convenios/migrations/0032_gescon_palavras_excluir.py new file mode 100644 index 0000000..e026b80 --- /dev/null +++ b/sigi/apps/convenios/migrations/0032_gescon_palavras_excluir.py @@ -0,0 +1,22 @@ +# Generated by Django 4.1.2 on 2022-11-08 19:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("convenios", "0031_alter_projeto_modelo_minuta_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="gescon", + name="palavras_excluir", + field=models.TextField( + default="DTCOM", + help_text="Palavras que não podem aparecer no campo OBJETO dos dados do Gescon.", + verbose_name="palavras de exclusão", + ), + ), + ] diff --git a/sigi/apps/convenios/models.py b/sigi/apps/convenios/models.py index 5d660ea..02630af 100644 --- a/sigi/apps/convenios/models.py +++ b/sigi/apps/convenios/models.py @@ -1,5 +1,6 @@ import re import requests +from pathlib import Path from django.db import models from django.db.models import Q, fields from django.core.mail import send_mail @@ -97,6 +98,9 @@ class Projeto(models.Model): encoding="utf-8", base_url=path, ) + file_name = Path(file_object.path) + if not file_name.parent.exists(): + file_name.parent.mkdir(parents=True, exist_ok=True) if file_object.closed: file_object.open(mode="wb") pdf.write_pdf(target=file_object) @@ -132,7 +136,9 @@ class Projeto(models.Model): cell.paragraphs, doc_context, ) - + file_path = Path(file_path) + if not file_path.parent.exists(): + file_path.mkdir(parents=True, exist_ok=True) doc.save(file_path) def processa_paragrafos(self, paragrafos, context): @@ -523,6 +529,17 @@ class Gescon(models.Model): "importado." ), ) + palavras_excluir = models.TextField( + _("palavras de exclusão"), + default="DTCOM", + help_text=_( + "Palavras que não podem aparecer no campo OBJETO dos dados do " + "Gescon." + "" + ), + ) orgaos_gestores = models.TextField( _("Órgãos gestores"), default="SCCO", @@ -615,7 +632,8 @@ class Gescon(models.Model): ) return - palavras = self.palavras.split() + palavras = self.palavras.splitlines() + excludentes = self.palavras_excluir.splitlines() orgaos = self.orgaos_gestores.split() subespecies = {tuple(s.split("=")) for s in self.subespecies.split()} lista_cnpj = { @@ -658,12 +676,15 @@ class Gescon(models.Model): nossos = [ c for c in contratos - if any(palavra in c["objeto"] for palavra in palavras) - or any( - orgao in c["orgaosGestoresTitulares"] - for orgao in orgaos - if c["orgaosGestoresTitulares"] is not None + if ( + any(palavra in c["objeto"] for palavra in palavras) + or any( + orgao in c["orgaosGestoresTitulares"] + for orgao in orgaos + if c["orgaosGestoresTitulares"] is not None + ) ) + and not any(palavra in c["objeto"] for palavra in excludentes) ] self.add_message( diff --git a/sigi/apps/ocorrencias/views.py b/sigi/apps/ocorrencias/views.py index b8533f3..57c2060 100644 --- a/sigi/apps/ocorrencias/views.py +++ b/sigi/apps/ocorrencias/views.py @@ -830,7 +830,7 @@ class SolicitaConvenioCreateView(ContatoInterlegisViewMixin, UpdateView): if self.object.casa_brasao: self.object.casa_brasao.delete(save=True) else: - self.object.casa_bocorrenciarasao = brasao + self.object.casa_brasao = brasao self.infos["casa_legislativa"] = cleaned return "presidente"