diff --git a/requirements/requirements.txt b/requirements/requirements.txt index a60ca4e8c..e613509e7 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,5 +1,5 @@ django==2.2.13 -django-haystack==2.8.1 +django-haystack==3.0 django-filter==2.0.0 djangorestframework==3.9.1 dj-database-url==0.5.0 diff --git a/sapl/base/views.py b/sapl/base/views.py index ad0051d9f..df07e3764 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -2207,6 +2207,7 @@ class AppConfigCrud(CrudAux): def get(self, request, *args, **kwargs): return HttpResponseRedirect(reverse('sapl.base:appconfig_create')) + class HackedFacetedModelSearchForm(FacetedModelSearchForm): """ 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) -# 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): +class SaplSearchView(FacetedSearchView): results_per_page = 10 + facet_fields = ['ano', 'tipo'] + form_class = HackedFacetedModelSearchForm def get_context(self): context = super(SaplSearchView, self).get_context() diff --git a/sapl/templates/search/search.html b/sapl/templates/search/search.html index d6c31da0a..f2ea61316 100644 --- a/sapl/templates/search/search.html +++ b/sapl/templates/search/search.html @@ -33,16 +33,44 @@
{% if query %} + +

Por ano

+ +
+
+ {% if facets.fields.ano %} +
ano
+ {% for ano in facets.fields.ano|slice:":5" %} +
{{ ano.0 }} ({{ ano.1 }})
+ {% endfor %} + {% else %} +

Sem facet de ano.

+ {% endif %} +
+
+
+
+ {% if facets.fields.tipo %} +
tipo
+ {% for tipo in facets.fields.tipo|slice:":5" %} +
{{ tipo.0 }} ({{ tipo.1 }})
+ {% endfor %} + {% else %} +

Sem facet de tipo.

+ {% endif %} +
+
+ - - {% for result in page.object_list %} + {% for result in page_obj.object_list %}

Resultados - Foram encontrados {{ page.paginator.count }} registros
- {% if page.paginator.count %} - Registros {{ page.start_index }} a {{ page.end_index }} de {{ page.paginator.count }} +

Resultados - Foram encontrados {{ page_obj.paginator.count }} registros
+ {% if page_obj.paginator.count %} + Registros {{ page_obj.start_index }} a {{ page_obj.end_index }} de {{ page_obj.paginator.count }} {% endif %}

{% if result.object|search_get_model == 'm' %} @@ -91,15 +119,15 @@ {% endfor %}
- {% if page.has_previous or page.has_next %} + {% if page_obj.has_previous or page_obj.has_next %}
- {% if page.has_previous %} - - {% endif %}« Anterior{% if page.has_previous %}{% endif %} + {% if page_obj.has_previous %} + + {% endif %}« Anterior{% if page_obj.has_previous %}{% endif %} | - {% if page.has_next %} - - {% endif %}Próxima »{% if page.has_next %}{% endif %} + {% if page_obj.has_next %} + + {% endif %}Próxima »{% if page_obj.has_next %}{% endif %}
{% endif %} {% else %}