Browse Source

WIP

faceted-search-2
eribeiro 4 years ago
parent
commit
78f992c7c0
  1. 2
      requirements/requirements.txt
  2. 25
      sapl/base/views.py
  3. 50
      sapl/templates/search/search.html

2
requirements/requirements.txt

@ -1,5 +1,5 @@
django==2.2.13 django==2.2.13
django-haystack==2.8.1 django-haystack==3.0
django-filter==2.0.0 django-filter==2.0.0
djangorestframework==3.9.1 djangorestframework==3.9.1
dj-database-url==0.5.0 dj-database-url==0.5.0

25
sapl/base/views.py

@ -2207,6 +2207,7 @@ class AppConfigCrud(CrudAux):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
return HttpResponseRedirect(reverse('sapl.base:appconfig_create')) return HttpResponseRedirect(reverse('sapl.base:appconfig_create'))
class HackedFacetedModelSearchForm(FacetedModelSearchForm): class HackedFacetedModelSearchForm(FacetedModelSearchForm):
""" """
Este é um hack vindo de https://github.com/django-haystack/django-haystack/pull/705 Este é um hack vindo de https://github.com/django-haystack/django-haystack/pull/705
@ -2219,28 +2220,10 @@ class HackedFacetedModelSearchForm(FacetedModelSearchForm):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# class SaplSearchView(FacetedSearchView): class SaplSearchView(FacetedSearchView):
# results_per_page = 10
# facet_fields = ['ano', 'tipo']
# form_class = HackedFacetedModelSearchForm
#
# def get_context(self):
# context = super(SaplSearchView, self).get_context()
#
# if 'models' in self.request.GET:
# models = self.request.GET.getlist('models')
# else:
# models = []
#
# context['models'] = ''
#
# for m in models:
# context['models'] = context['models'] + '&models=' + m
#
# return context
class SaplSearchView(SearchView):
results_per_page = 10 results_per_page = 10
facet_fields = ['ano', 'tipo']
form_class = HackedFacetedModelSearchForm
def get_context(self): def get_context(self):
context = super(SaplSearchView, self).get_context() context = super(SaplSearchView, self).get_context()

50
sapl/templates/search/search.html

@ -33,16 +33,44 @@
</div> </div>
</br> </br>
{% if query %} {% if query %}
<h2>Por ano</h2>
<div>
<dl>
{% if facets.fields.ano %}
<dt>ano</dt>
{% for ano in facets.fields.ano|slice:":5" %}
<dd><a href="{{ request.get_full_path }}&amp;selected_facets=ano:{{ ano.0|urlencode }}">{{ ano.0 }}</a> ({{ ano.1 }})</dd>
{% endfor %}
{% else %}
<p>Sem facet de ano.</p>
{% endif %}
</dl>
</div>
<div>
<dl>
{% if facets.fields.tipo %}
<dt>tipo</dt>
{% for tipo in facets.fields.tipo|slice:":5" %}
<dd><a href="{{ request.get_full_path }}&amp;selected_facets=tipo:{{ tipo.0|urlencode }}">{{ tipo.0 }}</a> ({{ tipo.1 }})</dd>
{% endfor %}
{% else %}
<p>Sem facet de tipo.</p>
{% endif %}
</dl>
</div>
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">
<thead class="thead-default"> <thead class="thead-default">
<tr><td><h3>Resultados - Foram encontrados {{ page.paginator.count }} registros <br/> <tr><td><h3>Resultados - Foram encontrados {{ page_obj.paginator.count }} registros <br/>
{% if page.paginator.count %} {% if page_obj.paginator.count %}
Registros {{ page.start_index }} a {{ page.end_index }} de {{ page.paginator.count }} Registros {{ page_obj.start_index }} a {{ page_obj.end_index }} de {{ page_obj.paginator.count }}
{% endif %} {% endif %}
</h3></td></tr> </h3></td></tr>
</thead> </thead>
{% for result in page.object_list %} {% for result in page_obj.object_list %}
<tr> <tr>
<td> <td>
{% if result.object|search_get_model == 'm' %} {% if result.object|search_get_model == 'm' %}
@ -91,15 +119,15 @@
{% endfor %} {% endfor %}
</table> </table>
{% if page.has_previous or page.has_next %} {% if page_obj.has_previous or page_obj.has_next %}
<div> <div>
{% if page.has_previous %} {% if page_obj.has_previous %}
<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}{{ models }}"> <a href="{{ request.get_full_path }}&amp;page={{ page_obj.previous_page_number }}{{ models }}">
{% endif %}&laquo; Anterior{% if page.has_previous %}</a>{% endif %} {% endif %}&laquo; Anterior{% if page_obj.has_previous %}</a>{% endif %}
| |
{% if page.has_next %} {% if page_obj.has_next %}
<a href="?q={{ query }}&amp;page={{ page.next_page_number }}{{ models }}"> <a href="{{ request.get_full_path }}&amp;page={{ page_obj.next_page_number }}{{ models }}">
{% endif %}Próxima &raquo;{% if page.has_next %}</a>{% endif %} {% endif %}Próxima &raquo;{% if page_obj.has_next %}</a>{% endif %}
</div> </div>
{% endif %} {% endif %}
{% else %} {% else %}

Loading…
Cancel
Save