From a46f17871e7a9192424eb8c70a2fb68a014adac7 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 29 Mar 2017 13:10:57 -0300 Subject: [PATCH] Adiciona signals para atualizar o index --- sapl/base/search_indexes.py | 2 ++ sapl/materia/apps.py | 3 +++ sapl/materia/signals.py | 29 +++++++++++++++++++++++++++++ sapl/templates/search/search.html | 14 ++++++++++++-- 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 sapl/materia/signals.py diff --git a/sapl/base/search_indexes.py b/sapl/base/search_indexes.py index ce1de49ab..cd4b4ebaf 100644 --- a/sapl/base/search_indexes.py +++ b/sapl/base/search_indexes.py @@ -36,6 +36,8 @@ class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable): arquivo.path).decode( 'utf-8').replace('\n', ' ') + extracted_data = extracted_data.replace('\t', ' ') + t = loader.select_template(( 'search/indexes/' + self.template_name, )) data['text'] = t.render(Context({'object': obj, diff --git a/sapl/materia/apps.py b/sapl/materia/apps.py index 3ac053d1b..ecc8d09de 100644 --- a/sapl/materia/apps.py +++ b/sapl/materia/apps.py @@ -6,3 +6,6 @@ class AppConfig(apps.AppConfig): name = 'sapl.materia' label = 'materia' verbose_name = _('Matéria') + + def ready(self): + from . import signals diff --git a/sapl/materia/signals.py b/sapl/materia/signals.py new file mode 100644 index 000000000..96ff85dea --- /dev/null +++ b/sapl/materia/signals.py @@ -0,0 +1,29 @@ +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 MateriaLegislativa, DocumentoAcessorio + + +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=MateriaLegislativa) +post_save.connect(save_texto, sender=DocumentoAcessorio) +post_delete.connect(delete_texto, sender=MateriaLegislativa) +post_delete.connect(delete_texto, sender=DocumentoAcessorio) diff --git a/sapl/templates/search/search.html b/sapl/templates/search/search.html index 0040a0d18..ed66e5a83 100644 --- a/sapl/templates/search/search.html +++ b/sapl/templates/search/search.html @@ -4,6 +4,7 @@ {% block base_content %}

Pesquisa Textual

+
@@ -51,13 +52,22 @@ {% if result.object|search_get_model == 'm' %}

Matéria Legislativa: {{ result.object }}
- Texto Original: Clique aqui
+ + {% if result.object.texto_original %} + Texto Original: Clique aqui
+ {% else %} + O texto desta matéria foi removido recentemente. Em breve ela sairá desta listagem.
+ {% endif %}

{% elif result.object|search_get_model == 'd' %}

Documento Acessório: {{ result.object }}
- Texto Original: Clique aqui
+ {% if result.object.arquivo %} + Texto Original: Clique aqui
+ {% else %} + O texto deste documento foi removido recentemente. Em breve ele sairá desta listagem.
+ {% endif %}

{% endif %}