Browse Source

WIP

faceted-search-2
eribeiro 4 years ago
parent
commit
a87df5e55e
  1. 2
      sapl/base/urls.py
  2. 49
      sapl/base/views.py

2
sapl/base/urls.py

@ -175,7 +175,7 @@ urlpatterns = [
name='login'), name='login'),
url(r'^logout/$', views.LogoutView.as_view(), {'next_page': LOGOUT_REDIRECT_URL}, name='logout'), url(r'^logout/$', views.LogoutView.as_view(), {'next_page': LOGOUT_REDIRECT_URL}, name='logout'),
url(r'^sistema/search/', SaplSearchView(), name='haystack_search'), url(r'^sistema/search/', SaplSearchView.as_view(), name='haystack_search'),
# Folhas XSLT e extras referenciadas por documentos migrados do sapl 2.5 # Folhas XSLT e extras referenciadas por documentos migrados do sapl 2.5
url(r'^(sapl/)?XSLT/HTML/(?P<path>.*)$', RedirectView.as_view( url(r'^(sapl/)?XSLT/HTML/(?P<path>.*)$', RedirectView.as_view(

49
sapl/base/views.py

@ -29,7 +29,7 @@ from django.views.generic import (CreateView, DetailView, DeleteView, FormView,
from django.views.generic.base import RedirectView, TemplateView from django.views.generic.base import RedirectView, TemplateView
from django_filters.views import FilterView from django_filters.views import FilterView
from haystack.forms import FacetedModelSearchForm from haystack.forms import FacetedModelSearchForm
from haystack.views import SearchView, FacetedSearchView from haystack.generic_views import SearchView, FacetedSearchView
from haystack.query import SearchQuerySet from haystack.query import SearchQuerySet
from sapl.relatorios.views import (relatorio_materia_em_tramitacao, relatorio_materia_por_autor, from sapl.relatorios.views import (relatorio_materia_em_tramitacao, relatorio_materia_por_autor,
@ -2207,21 +2207,44 @@ 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 SaplSearchView(FacetedSearchView): """
results_per_page = 10 Este é um hack vindo de https://github.com/django-haystack/django-haystack/pull/705
facet_fields = ['ano', 'tipo'] para possibilitar o uso de FacetedSearchView com FacetedModelSearchView. QUANDO/SE
form_class = FacetedModelSearchForm o PR https://github.com/django-haystack/django-haystack/pull/1400 for integrado ao
Haystack essa classe pode ser substituida por FacetedModelSearchForm
"""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(SaplSearchView).__init__(*args, **kwargs) self.selected_facets = kwargs.pop("selected_facets", [])
import ipdb; ipdb.set_trace() 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):
results_per_page = 10
def get_context(self): def get_context(self):
context = super(SaplSearchView, self).get_context() context = super(SaplSearchView, self).get_context()
import ipdb; ipdb.set_trace()
if 'models' in self.request.GET: if 'models' in self.request.GET:
models = self.request.GET.getlist('models') models = self.request.GET.getlist('models')
else: else:
@ -2234,10 +2257,6 @@ class SaplSearchView(FacetedSearchView):
return context return context
def get_context_data(self, **kwargs):
context = super(SaplSearchView, self).get_context_data(**kwargs)
import ipdb; ipdb.set_trace()
return context
class AlterarSenha(FormView): class AlterarSenha(FormView):
from sapl.settings import LOGIN_URL from sapl.settings import LOGIN_URL

Loading…
Cancel
Save