:setting:`SOBOL_USE_EVENTLET`
If :mod:`eventlet` is installed and this setting is ``True``, sobol web searches will use :mod:`eventlet.green.urllib2` instead of the built-in :mod:`urllib2` module. Default: ``False``.
+Templates
+---------
+
+For convenience, :mod:`.sobol` provides a template at ``sobol/search/_list.html`` which can be used with an ``{% include %}`` tag inside a full search page template to list the search results. The ``_list.html`` template also uses a basic jQuery script (``static/sobol/ajax_search.js``) to handle AJAX search result loading if the AJAX API of the current :class:`.SearchView` is enabled. If you want to use ``_list.html``, but want to provide your own version of jQuery or your own AJAX loading script, or if you want to include the basic script somewhere else (like inside the ``<head>``) simply do the following::
+
+ {% include "sobol/search/_list.html" with suppress_scripts=1 %}
+
"""
from philo.contrib.sobol.search import *
\ No newline at end of file
search_instance = get_search_instance(slug, search_string)
return HttpResponse(json.dumps({
+ 'search': search_instance.slug,
'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,
cached = cache.get(key)
if cached:
return cached
- return search(search_arg)
+ instance = search(search_arg)
+ instance.slug = slug
+ return instance
(function($){
- var sobol = window.sobol = {}
- sobol.setup = function(){
+ var sobol = window.sobol = {};
+ sobol.search = function(){
var searches = sobol.searches = $('article.search');
- for (i=0;i<searches.length;i++) {
+ for (var i=0;i<searches.length;i++) {
(function(){
var s = searches[i];
$.ajax({
url: s.getAttribute('data-url'),
dataType: 'json',
success: function(data){
- $(s).removeClass('loading')
- if (data['results'].length) {
- s.innerHTML += "<dl>" + data['results'].join("") + "</dl>";
- if(data['hasMoreResults'] && data['moreResultsURL']) s.innerHTML += "<footer><p><a href='" + data['moreResultsURL'] + "'>See more results</a></p></footer>";
- } else {
- $(s).addClass('empty')
- s.innerHTML += "<p>No results found.</p>"
- }
+ sobol.onSuccess($(s), data);
},
error: function(data, textStatus, errorThrown){
- $(s).removeClass('loading');
- text = errorThrown ? errorThrown : textStatus ? textStatus : "Error occurred."
- if (errorThrown) {
- s.innerHTML += "<p>" + errorThrown + "</p>"
- };
+ sobol.onError($(s), textStatus, errorThrown);
}
});
}());
};
+ }
+ sobol.onSuccess = function(ele, data){
+ // hook for success!
+ ele.removeClass('loading')
+ if (data['results'].length) {
+ ele[0].innerHTML += "<dl>" + data['results'].join("") + "</dl>";
+ if(data['hasMoreResults'] && data['moreResultsURL']) ele[0].innerHTML += "<footer><p><a href='" + data['moreResultsURL'] + "'>See more results</a></p></footer>";
+ } else {
+ ele.addClass('empty');
+ ele[0].innerHTML += "<p>No results found.</p>";
+ ele.slideUp();
+ }
};
- $(sobol.setup);
+ sobol.onError = function(ele, textStatus, errorThrown){
+ // Hook for error...
+ ele.removeClass('loading');
+ text = errorThrown ? errorThrown : textStatus ? textStatus : "Error occurred.";
+ ele[0].innerHTML += "<p>" + text + "</p>";
+ };
+ $(sobol.search);
}(jQuery));
\ No newline at end of file
{% with node.view.enable_ajax_api as ajax %}
-{% if ajax %}<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script><script type="text/javascript" src="{{ STATIC_URL }}sobol/ajax_search.js"></script>{% endif %}
+{% if ajax and not suppress_scripts %}<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script><script type="text/javascript" src="{{ STATIC_URL }}sobol/ajax_search.js"></script>{% endif %}
{% for search in searches %}
-<article {% if ajax %}class="search loading {{ search.slug }}" data-url="{{ search.ajax_api_url }}" data-title="{{ search }}"{% else %}class="search {{ search.slug }}"{% endif %}>
+<article {% if ajax %}class="search loading {{ search.slug }}" data-url="{{ search.ajax_api_url }}"{% else %}class="search {{ search.slug }}{% if not search.results %} empty{% endif %}"{% endif %}>
<header>
<a name='{{ search.slug }}'></a>
<h1>{{ search }}</h1>
</header>
{% if not ajax %}
- <dl>
- {% for result in search.results %}
- {{ result }}
- {% endfor %}
- </dl>
- {% if search.has_more_results and search.more_results_url %}
- <footer>
- <p><a href="?{{ search.more_results_querydict.urlencode }}">See more results</a></p>
- </footer>
+ {% if search.results %}
+ <dl>
+ {% for result in search.results %}
+ {{ result }}
+ {% endfor %}
+ </dl>
+ {% if search.has_more_results and search.more_results_url %}
+ <footer>
+ <p><a href="?{{ search.more_results_querydict.urlencode }}">See more results</a></p>
+ </footer>
+ {% endif %}
+ {% else %}
+ <p>No results found.</p>
{% endif %}
{% endif %}
</article>