Browse Source

Merge db74e7ad45 into 0961ad4af5

pull/968/merge
Edward 9 years ago
committed by GitHub
parent
commit
361946693a
  1. 2
      .gitignore
  2. 5
      requirements/requirements.txt
  3. 31
      sapl/materia/search_indexes.py
  4. 2
      sapl/materia/urls.py
  5. 19
      sapl/settings.py
  6. 7
      sapl/templates/search/indexes/materia/documentoacessorio_text.txt
  7. 42
      sapl/templates/search/search.html

2
.gitignore

@ -24,6 +24,8 @@ var/
.installed.cfg .installed.cfg
*.egg *.egg
whoosh_index/
# PyInstaller # PyInstaller
# Usually these files are written by a python script from a template # Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it. # before PyInstaller builds the exe, so as to inject date/other infos into it.

5
requirements/requirements.txt

@ -13,6 +13,7 @@ django-extensions==1.6.7
django-extra-views==0.8.0 django-extra-views==0.8.0
django-filter==0.15.3 django-filter==0.15.3
django-floppyforms==1.6.2 django-floppyforms==1.6.2
django-haystack
django-model-utils==2.5 django-model-utils==2.5
django-sass-processor==0.4.6 django-sass-processor==0.4.6
djangorestframework djangorestframework
@ -29,3 +30,7 @@ unipath==1.1
python-magic==0.4.12 python-magic==0.4.12
gunicorn==19.6.0 gunicorn==19.6.0
django-reversion==2.0.8 django-reversion==2.0.8
whoosh
pysolr
elasticsearch
textract

31
sapl/materia/search_indexes.py

@ -0,0 +1,31 @@
from haystack import indexes
from sapl.materia.models import DocumentoAcessorio
class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
nome = indexes.CharField(model_attr='nome')
autor = indexes.CharField(model_attr='autor')
# def prepare(self, obj):
# data = super(DocumentoAcessorioIndex, self).prepare(obj)
# if obj.arquivo is not None:
# file_data = self._get_backend(None).extract_file_contents(
# obj.arquivo,
# )
# template = loader.select_template(
# ("search/indexes/materia/documentoacessorio_text.txt", ),
# )
#
# data["text"] = template.render(Context({
# "object": obj,
# "file_data": file_data,
# }))
#
# return data
def get_model(self):
return DocumentoAcessorio
def index_queryset(self, using=None):
return self.get_model().objects.all()

2
sapl/materia/urls.py

@ -67,6 +67,8 @@ urlpatterns_materia = [
name='primeira_tramitacao_em_lote'), name='primeira_tramitacao_em_lote'),
url(r'^materia/tramitacao-em-lote', TramitacaoEmLoteView.as_view(), url(r'^materia/tramitacao-em-lote', TramitacaoEmLoteView.as_view(),
name='tramitacao_em_lote'), name='tramitacao_em_lote'),
url(r'^materia/acessorio/search/', include('haystack.urls')),
] ]

19
sapl/settings.py

@ -14,6 +14,7 @@ See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
""" """
import logging import logging
import os
from decouple import config from decouple import config
from dj_database_url import parse as db_url from dj_database_url import parse as db_url
@ -77,6 +78,7 @@ INSTALLED_APPS = (
'easy_thumbnails', 'easy_thumbnails',
'floppyforms', 'floppyforms',
'sass_processor', 'sass_processor',
'haystack',
'rest_framework', 'rest_framework',
'reversion', 'reversion',
@ -173,6 +175,23 @@ SERVER_EMAIL = config('SERVER_EMAIL', cast=str, default='')
MAX_DOC_UPLOAD_SIZE = 5 * 1024 * 1024 # 5MB MAX_DOC_UPLOAD_SIZE = 5 * 1024 * 1024 # 5MB
MAX_IMAGE_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB MAX_IMAGE_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
},
# 'default': {
# 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
# 'URL': 'http://127.0.0.1:9200/',
# 'INDEX_NAME': 'products',
# },
# 'default': {
# 'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
# 'URL': 'http://127.0.0.1:8983/',
# 'INDEX_NAME': 'products',
# },
}
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/ # https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'pt-br' LANGUAGE_CODE = 'pt-br'

7
sapl/templates/search/indexes/materia/documentoacessorio_text.txt

@ -0,0 +1,7 @@
{{ object.tipo.sigla }}
{{ object.tipo.descricao }}
{{ object.materia.numero}}
{{ object.materia.ano}}
{{ object.nome }}
{{ object.data }}
{{ object.ementa }}

42
sapl/templates/search/search.html

@ -0,0 +1,42 @@
{% extends "crud/detail.html" %}
{% block detail_content %}
<h2>Search</h2>
<form method="get" action=".">
<table>
{{ form.as_table }}
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="Search">
</td>
</tr>
</table>
{% if query %}
<h3>Results</h3>
{% for result in page.object_list %}
<p>
<a href="{{ result.object.get_absolute_url }}">
{{ result.object.materia.numero}}/
{{ result.object.materia.ano }} -
{{ result.object.ementa }}
</a>
</p>
{% empty %}
<p>No results found.</p>
{% endfor %}
{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Anterior{% if page.has_previous %}</a>{% endif %}
|
{% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Próximo &raquo;{% if page.has_next %}</a>{% endif %}
</div>
{% endif %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
</form>
{% endblock %}
Loading…
Cancel
Save