X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/b294f0a6d6dee39995ba29fc83f39fd4733b46f3..fffac3a965cb9cf3dc7c97a0108d5304f22b486f:/philo/contrib/sobol/models.py diff --git a/philo/contrib/sobol/models.py b/philo/contrib/sobol/models.py index 82fe947..ee5f62e 100644 --- a/philo/contrib/sobol/models.py +++ b/philo/contrib/sobol/models.py @@ -151,18 +151,6 @@ class Click(models.Model): get_latest_by = 'datetime' -class RegistryChoiceField(SlugMultipleChoiceField): - def _get_choices(self): - if isinstance(self._choices, RegistryIterator): - return self._choices.copy() - elif hasattr(self._choices, 'next'): - choices, self._choices = itertools.tee(self._choices) - return choices - else: - return self._choices - choices = property(_get_choices) - - try: from south.modelsinspector import add_introspection_rules except ImportError: @@ -172,11 +160,11 @@ else: class SearchView(MultiView): - """Handles a view for the results of a search, and an AJAX API for asynchronous search result loading. This can be particularly useful if some searches are slow.""" + """Handles a view for the results of a search, anonymously tracks the selections made by end users, and provides an AJAX API for asynchronous search result loading. This can be particularly useful if some searches are slow.""" #: :class:`ForeignKey` to a :class:`.Page` which will be used to render the search results. results_page = models.ForeignKey(Page, related_name='search_results_related') - #: A class:`.SlugMultipleChoiceField` whose choices are the contents of the :class:`.SearchRegistry` - searches = RegistryChoiceField(choices=registry.iterchoices()) + #: A :class:`.SlugMultipleChoiceField` whose choices are the contents of :obj:`.sobol.search.registry` + searches = SlugMultipleChoiceField(choices=registry.iterchoices()) #: A :class:`BooleanField` which controls whether or not the AJAX API is enabled. #: #: .. note:: If the AJAX API is enabled, a ``ajax_api_url`` attribute will be added to each search instance containing the url and get parameters for an AJAX request to retrieve results for that search. @@ -207,14 +195,14 @@ 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``.""" + """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: - * A search has been initiated. In this case, a list of search instances will be added to the context as 'searches'. If :attr:`enable_ajax_api` is enabled, each instance will have an "ajax_api_url" attribute containing the url needed to make an AJAX request for the search results. + * A search has been initiated. In this case, a list of search instances will be added to the context as ``searches``. If :attr:`enable_ajax_api` is enabled, each instance will have an ``ajax_api_url`` attribute containing the url needed to make an AJAX request for the search results. * A link has been chosen. In this case, corresponding :class:`Search`, :class:`ResultURL`, and :class:`Click` instances will be created and the user will be redirected to the link's actual url. """ @@ -274,9 +262,12 @@ class SearchView(MultiView): results Contains the results of :meth:`.Result.get_context` for each result. - rendered Contains the results of :meth:`.Result.render` for each result. + hasMoreResults + ``True`` or ``False`` whether the search has more results according to :meth:`BaseSearch.has_more_results` + moreResultsURL + Contains None or a querystring which, once accessed, will note the :class:`Click` and redirect the user to a page containing more results. """ search_string = request.GET.get(SEARCH_ARG_GET_KEY) @@ -288,5 +279,7 @@ class SearchView(MultiView): return HttpResponse(json.dumps({ 'results': [result.get_context() for result in search_instance.results], - 'rendered': [result.render() 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, }), mimetype="application/json") \ No newline at end of file