X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/cc6dbd55a2af538657c288a709662b9c84949854..4fd0861aa9d51262d5afcdc40ea48e7ce7ec7aaa:/philo/contrib/sobol/models.py diff --git a/philo/contrib/sobol/models.py b/philo/contrib/sobol/models.py index 7687c09..27f91d1 100644 --- a/philo/contrib/sobol/models.py +++ b/philo/contrib/sobol/models.py @@ -11,7 +11,7 @@ from django.http import HttpResponseRedirect, Http404, HttpResponse from django.utils import simplejson as json from django.utils.datastructures import SortedDict -from philo.contrib.sobol import registry +from philo.contrib.sobol import registry, get_search_instance 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 @@ -206,10 +206,6 @@ class SearchView(MultiView): ) return urlpatterns - def get_search_instance(self, slug, search_string): - """Returns an instance of the :class:`.BaseSearch` subclass corresponding to ``slug`` in the :class:`.SearchRegistry` and instantiated 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: @@ -245,11 +241,12 @@ class SearchView(MultiView): search_instances = [] for slug in self.searches: - 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) if eventlet and not self.enable_ajax_api: pool = eventlet.GreenPool() @@ -284,14 +281,13 @@ class SearchView(MultiView): """ search_string = request.GET.get(SEARCH_ARG_GET_KEY) - if not request.is_ajax() or not self.enable_ajax_api or slug not in self.searches or search_string is None: + if not request.is_ajax() or not self.enable_ajax_api or slug not in registry or slug not in self.searches or search_string is None: raise Http404 - search_instance = self.get_search_instance(slug, search_string) + search_instance = get_search_instance(slug, search_string) return HttpResponse(json.dumps({ - 'results': [result.get_context() for result in search_instance.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, + 'results': [result.render() for result in search_instance.results], + 'hasMoreResults': search_instance.has_more_results, + 'moreResultsURL': (u"?%s" % search_instance.more_results_querydict.urlencode()) if search_instance.more_results_querydict else None, }), mimetype="application/json") \ No newline at end of file