Browse Source

Help para placeholders

pull/159/head
Sesostris Vieira 3 years ago
parent
commit
236ec8490d
  1. 48
      sigi/apps/convenios/models.py
  2. 21
      sigi/apps/home/templates/home/editor_help_snippet.html
  3. 31
      sigi/apps/home/views.py

48
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:<ul><li>{{ casa.nome }} para o"
" nome da Casa Legislativa / órgão</li>"
"<li>{{ casa.municipio.uf.sigla }} para a sigla da UF da "
"Casa legislativa</li><li>{{ presidente.nome }} "
"para o nome do presidente</li><li>{{ contato.nome }} para o nome "
"do contato Interlegis</li></ul>"
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",
]
),
],
)

21
sigi/apps/home/templates/home/editor_help_snippet.html

@ -0,0 +1,21 @@
Utilize os seguintes <a class="modal-trigger" href="#help_modal_{{ field_name }}"><i>placeholders</i></a>
<div id="help_modal_{{ field_name }}" class="modal">
<div class="modal-content">
<h5>Placeholders</h5>
<ul class="collection">
{% for placeholder in placeholders %}
<li class="collection-item"><b>{{ placeholder.0 }}</b>: {{ placeholder.1 }}</li>
{% endfor %}
</ul>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-small btn-flat">Fechar</a>
</div>
</div>
<script>
console.log("Rodou");
$(document).ready(function(){
M.Modal.init($('.modal'), {});
});
</script>

31
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},
)

Loading…
Cancel
Save