Browse Source

Implementa pesquisa textual para Normas Juridicas

pull/991/head
Eduardo Calil 8 years ago
parent
commit
886707899b
  1. 9
      sapl/base/search_indexes.py
  2. 3
      sapl/base/templatetags/common_tags.py
  3. 3
      sapl/norma/apps.py
  4. 6
      sapl/norma/models.py
  5. 27
      sapl/norma/signals.py
  6. 7
      sapl/templates/search/indexes/norma/normajuridica_text.txt
  7. 10
      sapl/templates/search/search.html

9
sapl/base/search_indexes.py

@ -4,6 +4,7 @@ import textract
from django.template import Context, loader
from haystack import indexes
from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa
from sapl.norma.models import NormaJuridica
class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable):
@ -60,3 +61,11 @@ class MateriaLegislativaIndex(DocumentoAcessorioIndex):
filename = 'texto_original'
model = MateriaLegislativa
template_name = 'materia/materialegislativa_text.txt'
class NormaJuridicaIndex(DocumentoAcessorioIndex):
text = indexes.CharField(document=True, use_template=True)
filename = 'texto_integral'
model = NormaJuridica
template_name = 'norma/normajuridica_text.txt'

3
sapl/base/templatetags/common_tags.py

@ -3,6 +3,7 @@ from django import template
from sapl.base.models import AppConfig
from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa
from sapl.norma.models import NormaJuridica
from sapl.parlamentares.models import Filiacao
register = template.Library()
@ -146,5 +147,7 @@ def search_get_model(object):
return 'm'
elif type(object) == DocumentoAcessorio:
return 'd'
elif type(object) == NormaJuridica:
return 'n'
return None

3
sapl/norma/apps.py

@ -6,3 +6,6 @@ class AppConfig(apps.AppConfig):
name = 'sapl.norma'
label = 'norma'
verbose_name = _('Norma Jurídica')
def ready(self):
from . import signals

6
sapl/norma/models.py

@ -7,7 +7,8 @@ from model_utils import Choices
from sapl.compilacao.models import TextoArticulado
from sapl.materia.models import MateriaLegislativa
from sapl.utils import RANGE_ANOS, YES_NO_CHOICES, texto_upload_path
from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, texto_upload_path,
restringe_tipos_de_arquivo_txt)
@reversion.register()
@ -70,7 +71,8 @@ class NormaJuridica(models.Model):
blank=True,
null=True,
upload_to=texto_upload_path,
verbose_name=_('Texto Integral'))
verbose_name=_('Texto Integral'),
validators=[restringe_tipos_de_arquivo_txt])
tipo = models.ForeignKey(
TipoNormaJuridica,
on_delete=models.PROTECT,

27
sapl/norma/signals.py

@ -0,0 +1,27 @@
from django.db.models.signals import post_delete, post_save
from sapl.settings import PROJECT_DIR
from subprocess import PIPE, call
from threading import Thread
from .models import NormaJuridica
class UpdateIndexCommand(Thread):
def run(self):
call([PROJECT_DIR.child('manage.py'), 'update_index'],
stdout=PIPE)
def save_texto(sender, instance, **kwargs):
update_index = UpdateIndexCommand()
update_index.start()
def delete_texto(sender, instance, **kwargs):
update_index = UpdateIndexCommand()
update_index.start()
post_save.connect(save_texto, sender=NormaJuridica)
post_delete.connect(delete_texto, sender=NormaJuridica)

7
sapl/templates/search/indexes/norma/normajuridica_text.txt

@ -0,0 +1,7 @@
{% for k, v in extracted.metadata.items %}
{% for val in v %}
{{ k }}: {{ val|safe }}
{% endfor %}
{% endfor %}
{{ extracted|striptags|safe }}

10
sapl/templates/search/search.html

@ -68,6 +68,16 @@
<strong>O texto deste documento foi removido recentemente. Em breve ele sairá desta listagem.</strong></br>
{% endif %}
</p>
{% elif result.object|search_get_model == 'n' %}
<p>
<strong> Norma Jurídica: </strong><a href="{% url 'sapl.norma:normajuridica_detail' result.object.pk %}">{{ result.object }}</a></br>
{% if result.object.texto_integral %}
<strong>Texto Original:</strong> <a href="{{result.object.texto_integral.url}}"> Clique aqui </a></br>
{% else %}
<strong>O texto desta norma foi removido recentemente. Em breve ela sairá desta listagem.</strong></br>
{% endif %}
</p>
{% endif %}
</td>
</tr>

Loading…
Cancel
Save