diff --git a/sigi/apps/convenios/models.py b/sigi/apps/convenios/models.py index a2f3313..9dc3e29 100644 --- a/sigi/apps/convenios/models.py +++ b/sigi/apps/convenios/models.py @@ -9,32 +9,58 @@ from django.urls import reverse from django.utils.formats import date_format from django.utils.translation import gettext as _ from tinymce.models import HTMLField +from sigi.apps.contatos.models import Municipio, UnidadeFederativa +from sigi.apps.eventos.models import Evento from sigi.apps.utils import to_ascii -from sigi.apps.casas.models import Orgao +from sigi.apps.casas.models import Funcionario, Orgao from sigi.apps.servidores.models import Servidor, Servico +from sigi.apps.home.views import editor_help class Projeto(models.Model): - MARKUP_HELP = _( - "Use as seguintes marcações:" + OFICIO_HELP = editor_help( + "texto_oficio", + [ + ("evento", Evento), + ("casa", Orgao), + ("presidente", Funcionario), + ("contato", Funcionario), + ("casa.municipio", Municipio), + ("casa.municipio.uf", UnidadeFederativa), + ("data", _("Data atual")), + ("doravante", _("CÂMARA ou ASSEMBLEIA")), + ], + ) + MINUTA_HELP = editor_help( + "modelo_minuta", + [ + ("evento", Evento), + ("casa", Orgao), + ("presidente", Funcionario), + ("contato", Funcionario), + ("casa.municipio", Municipio), + ("casa.municipio.uf", UnidadeFederativa), + ("data", _("Data atual")), + ("ente", _("Ente da federação (município/estado)")), + ("doravante", _("CÂMARA ou ASSEMBLEIA")), + ], ) nome = models.CharField(max_length=50) sigla = models.CharField(max_length=10) texto_oficio = HTMLField( - _("texto do ofício"), blank=True, help_text=MARKUP_HELP + _("texto do ofício"), blank=True, help_text=OFICIO_HELP ) modelo_minuta = models.FileField( _("Modelo de minuta"), blank=True, - help_text=MARKUP_HELP, + help_text=MINUTA_HELP, upload_to="convenios/minutas/", validators=[ - FileExtensionValidator, + FileExtensionValidator( + [ + "docx", + ] + ), ], ) diff --git a/sigi/apps/home/templates/home/editor_help_snippet.html b/sigi/apps/home/templates/home/editor_help_snippet.html new file mode 100644 index 0000000..06ac428 --- /dev/null +++ b/sigi/apps/home/templates/home/editor_help_snippet.html @@ -0,0 +1,21 @@ + +Utilize os seguintes placeholders + + \ No newline at end of file diff --git a/sigi/apps/home/views.py b/sigi/apps/home/views.py index 282b035..10970e3 100644 --- a/sigi/apps/home/views.py +++ b/sigi/apps/home/views.py @@ -4,16 +4,17 @@ import datetime from itertools import cycle from django.contrib.admin.sites import site from django.contrib.auth.decorators import login_required +from django.db import models from django.db.models import Q, Count from django.http import HttpResponse, HttpResponseForbidden, JsonResponse from django.shortcuts import render, get_object_or_404 +from django.template import Template, Context from django.template.loader import render_to_string from django.utils.translation import gettext as _ from django.views.decorators.cache import never_cache from django_weasyprint.views import WeasyTemplateResponse from sigi.apps.casas.models import TipoOrgao, Orgao from sigi.apps.contatos.models import UnidadeFederativa -from sigi.apps.convenios.models import Convenio, Projeto from sigi.apps.servicos.models import TipoServico from sigi.apps.servidores.models import Servidor from sigi.apps.utils import to_ascii @@ -476,6 +477,8 @@ def report_sem_convenio(request): def busca_informacoes_camara(): + from sigi.apps.convenios.models import Convenio, Projeto + camaras = Orgao.objects.filter(tipo__sigla="CM") convenios = Convenio.objects.filter(casa_legislativa__tipo__sigla="CM") projetos = Projeto.objects.all() @@ -714,3 +717,29 @@ def color_palete(): ) return (colors, highlights) + + +def editor_help(field_name, Field_list): + placeholders = [] + for name, detail in Field_list: + if type(detail) is str: + placeholders.append([f"{{{{ {name} }}}}", detail]) + else: + placeholders.append( + [ + f"{{{{ {name} }}}}", + detail._meta.verbose_name.capitalize(), + ] + ) + for field in detail._meta.fields: + if field.auto_created or type(field) is models.ForeignKey: + pass # Ignore FK and auto-PK + else: + placeholders.append( + [f"{{{{ {name}.{field.name} }}}}", field.verbose_name] + ) + + return render_to_string( + "home/editor_help_snippet.html", + {"field_name": field_name, "placeholders": placeholders}, + )