from philo.contrib.sobol.forms import SearchForm
from philo.contrib.sobol.utils import HASH_REDIRECT_GET_KEY, URL_REDIRECT_GET_KEY, SEARCH_ARG_GET_KEY, check_redirect_hash, RegistryIterator
from philo.exceptions import ViewCanNotProvideSubpath
from philo.contrib.sobol.forms import SearchForm
from philo.contrib.sobol.utils import HASH_REDIRECT_GET_KEY, URL_REDIRECT_GET_KEY, SEARCH_ARG_GET_KEY, check_redirect_hash, RegistryIterator
from philo.exceptions import ViewCanNotProvideSubpath
- def get_search_instance(self, slug, search_string):
- """Gets the :class:`.BaseSearch` subclass registered with :obj:`.sobol.search.registry` as ``slug`` and instantiates it with ``search_string``."""
- return registry[slug](search_string.lower())
-
def results_view(self, request, extra_context=None):
"""
Renders :attr:`results_page` with a context containing an instance of :attr:`search_form`. If the form was submitted and was valid, then one of two things has happened:
def results_view(self, request, extra_context=None):
"""
Renders :attr:`results_page` with a context containing an instance of :attr:`search_form`. If the form was submitted and was valid, then one of two things has happened:
- search_instance = self.get_search_instance(slug, search_string)
- search_instances.append(search_instance)
+ if slug in registry:
+ search_instance = get_search_instance(slug, search_string)
+ search_instances.append(search_instance)
- if self.enable_ajax_api:
- search_instance.ajax_api_url = "%s?%s=%s" % (self.reverse('ajax_api_view', kwargs={'slug': slug}, node=request.node), SEARCH_ARG_GET_KEY, search_string)
+ if self.enable_ajax_api:
+ search_instance.ajax_api_url = "%s?%s=%s" % (self.reverse('ajax_api_view', kwargs={'slug': slug}, node=request.node), SEARCH_ARG_GET_KEY, search_string)
def ajax_api_view(self, request, slug, extra_context=None):
"""
def ajax_api_view(self, request, slug, extra_context=None):
"""
- Contains None or a querystring which, once accessed, will note the :class:`Click` and redirect the user to a page containing more results.
+ Contains ``None`` or a querystring which, once accessed, will note the :class:`Click` and redirect the user to a page containing more results.
- 'rendered': [result.render() for result in search_instance.results],
- 'hasMoreResults': search.has_more_results(),
- 'moreResultsURL': (u"?%s" % search.more_results_querydict.urlencode()) if search.more_results_querydict else None,
+ 'hasMoreResults': search_instance.has_more_results,
+ 'moreResultsURL': search_instance.more_results_url,
}), mimetype="application/json")
\ No newline at end of file
}), mimetype="application/json")
\ No newline at end of file