Initial changes to support haystack from the dynamic search app
This commit is contained in:
38
apps/dynamic_search/templates/search/search.html
Normal file
38
apps/dynamic_search/templates/search/search.html
Normal file
@@ -0,0 +1,38 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% load search_tags %}
|
||||
{% block title %} :: {% trans "Search results" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if form %}
|
||||
{% include "search_results_subtemplate.html" %}
|
||||
{% endif %}
|
||||
{% if query %}
|
||||
{% with list_title as title %}
|
||||
{% include "generic_list_subtemplate.html" %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% if not form and not query %}
|
||||
{% include "generic_list_subtemplate.html" %}
|
||||
{% endif %}
|
||||
|
||||
{% comment %}
|
||||
|
||||
{% for result in page.object_list %}
|
||||
{% with result|search_include as fragment %}
|
||||
{% include fragment %}
|
||||
{% endwith %}
|
||||
{% empty %}
|
||||
<p>No results found.</p>
|
||||
{% endfor %}
|
||||
|
||||
{% endcomment %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
{% if query %}
|
||||
{% blocktrans %}Elapsed time: {{ elapsed_time }} seconds{% endblocktrans %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
{% block title %} :: {% trans "Search results" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if form %}
|
||||
{% include "search_results_subtemplate.html" %}
|
||||
{% endif %}
|
||||
@@ -12,6 +13,7 @@
|
||||
{% if not form and not query_string %}
|
||||
{% include "generic_list_subtemplate.html" %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from django.conf.urls.defaults import patterns, url
|
||||
|
||||
from .views import CustomSearchView
|
||||
|
||||
urlpatterns = patterns('dynamic_search.views',
|
||||
url(r'^$', 'search', (), 'search'),
|
||||
url(r'^$', CustomSearchView(), (), 'search'),
|
||||
url(r'^advanced/$', 'search', {'advanced': True}, 'search_advanced'),
|
||||
url(r'^again/$', 'search_again', (), 'search_again'),
|
||||
url(r'^results/$', 'results', (), 'results'),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import datetime
|
||||
import urlparse
|
||||
|
||||
from django.shortcuts import render_to_response
|
||||
@@ -9,6 +10,8 @@ from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.http import urlencode
|
||||
|
||||
from haystack.views import SearchView
|
||||
|
||||
from dynamic_search.models import RecentSearch
|
||||
from dynamic_search.api import perform_search
|
||||
from dynamic_search.forms import SearchForm, AdvancedSearchForm
|
||||
@@ -16,6 +19,43 @@ from dynamic_search.conf.settings import SHOW_OBJECT_TYPE
|
||||
from dynamic_search.conf.settings import LIMIT
|
||||
|
||||
|
||||
class CustomSearchView(SearchView):
|
||||
def __call__(self, *args, **kwargs):
|
||||
self.start_time = datetime.datetime.now()
|
||||
|
||||
return super(CustomSearchView, self).__call__(*args, **kwargs)
|
||||
|
||||
def create_response(self):
|
||||
"""
|
||||
Generates the actual HttpResponse to send back to the user.
|
||||
"""
|
||||
#(paginator, page) = self.build_page()
|
||||
|
||||
context = {
|
||||
'query': self.query,
|
||||
'form': self.form,
|
||||
'object_list': [result.object for result in self.results],
|
||||
#'page': page,
|
||||
#'paginator': paginator,
|
||||
'suggestion': None,
|
||||
'submit_label': _(u'Search'),
|
||||
'submit_icon_famfam': 'zoom',
|
||||
'form_title': _(u'Search'),
|
||||
'form_hide_required_text': True,
|
||||
'list_title': _(u'results for: %s') % self.query,
|
||||
'hide_links': True,
|
||||
'multi_select_as_buttons': True,
|
||||
'elapsed_time': unicode(datetime.datetime.now() - self.start_time).split(':')[2]
|
||||
|
||||
}
|
||||
|
||||
#if self.results and hasattr(self.results, 'query') and self.results.query.backend.include_spelling:
|
||||
# context['suggestion'] = self.form.get_suggestion()
|
||||
|
||||
context.update(self.extra_context())
|
||||
return render_to_response(self.template, context, context_instance=self.context_class(self.request))
|
||||
|
||||
|
||||
def results(request, extra_context=None):
|
||||
context = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user