Added new setting: side bar search box
This commit is contained in:
@@ -1,6 +1 @@
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from common.api import register_menu
|
||||
|
||||
register_menu([
|
||||
{'text':_(u'search'), 'view':'search', 'famfam':'zoom', 'position':2},
|
||||
])
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %} :: {% trans "Search results" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% with "get" as submit_method %}
|
||||
{% with form_title as title %}
|
||||
{% include "generic_form_subtemplate.html" %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
|
||||
{% if query_string %}
|
||||
{% include "generic_list_subtemplate.html" %}
|
||||
{% if form %}
|
||||
{% include "search_results_subtemplate.html" %}
|
||||
{% endif %}
|
||||
|
||||
{% if query_string %}
|
||||
{% include "generic_list_subtemplate.html" %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
{% if query_string %}
|
||||
{% blocktrans %}Elapsed time: {{ time_delta }} seconds{% endblocktrans %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{% with "get" as submit_method %}
|
||||
{% with form_title as title %}
|
||||
{% include "generic_form_subtemplate.html" %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
0
apps/dynamic_search/templatetags/__init__.py
Normal file
0
apps/dynamic_search/templatetags/__init__.py
Normal file
20
apps/dynamic_search/templatetags/search_tags.py
Normal file
20
apps/dynamic_search/templatetags/search_tags.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django.core.urlresolvers import reverse, NoReverseMatch
|
||||
from django.template import TemplateSyntaxError, Library, \
|
||||
VariableDoesNotExist, Node, Variable
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from dynamic_search.forms import SearchForm
|
||||
|
||||
|
||||
register = Library()
|
||||
|
||||
@register.inclusion_tag('search_results_subtemplate.html', takes_context=True)
|
||||
def search_form(context):
|
||||
context.update({
|
||||
'form':SearchForm(initial={'q':context.get('query_string', '')}),
|
||||
'request':context['request'],
|
||||
'MEDIA_URL':context['MEDIA_URL'],
|
||||
'form_action':reverse('results'),
|
||||
'form_title':_(u'Search')
|
||||
})
|
||||
return context
|
||||
@@ -3,6 +3,7 @@ from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('dynamic_search.views',
|
||||
url(r'^search/$', 'search', (), 'search'),
|
||||
url(r'^results/$', 'results', (), 'results'),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,57 @@ from forms import SearchForm
|
||||
from conf.settings import SHOW_OBJECT_TYPE
|
||||
|
||||
|
||||
def results(request, form=None):
|
||||
query_string = ''
|
||||
context = {}
|
||||
|
||||
result_count = 0
|
||||
if ('q' in request.GET) and request.GET['q'].strip():
|
||||
query_string = request.GET['q']
|
||||
try:
|
||||
model_list, flat_list, shown_result_count, total_result_count, elapsed_time = perform_search(query_string)
|
||||
if shown_result_count != total_result_count:
|
||||
title = _(u'results with: %s (showing only %s out of %s)') % (query_string, shown_result_count, total_result_count)
|
||||
else:
|
||||
title = _(u'results with: %s') % query_string
|
||||
context.update({
|
||||
'found_entries': model_list,
|
||||
'object_list':flat_list,
|
||||
'title':title,
|
||||
'time_delta':elapsed_time,
|
||||
})
|
||||
|
||||
except Exception, e:
|
||||
if settings.DEBUG:
|
||||
raise
|
||||
elif request.user.is_staff or request.user.is_superuser:
|
||||
messages.error(request, _(u'Search error: %s') % e)
|
||||
|
||||
context.update({
|
||||
'query_string':query_string,
|
||||
'form':form,
|
||||
'form_title':_(u'Search'),
|
||||
'hide_header':True,
|
||||
})
|
||||
|
||||
if SHOW_OBJECT_TYPE:
|
||||
context.update({'extra_columns':
|
||||
[{'name':_(u'type'), 'attribute':lambda x:x._meta.verbose_name[0].upper() + x._meta.verbose_name[1:]}]})
|
||||
|
||||
return render_to_response('search_results.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
|
||||
def search(request):
|
||||
if ('q' in request.GET) and request.GET['q'].strip():
|
||||
query_string = request.GET['q']
|
||||
form = SearchForm(initial={'q':query_string})
|
||||
return results(request, form=form)
|
||||
else:
|
||||
form = SearchForm()
|
||||
return results(request, form=form)
|
||||
"""
|
||||
def search(request):
|
||||
query_string = ''
|
||||
context = {}
|
||||
@@ -52,3 +103,4 @@ def search(request):
|
||||
|
||||
return render_to_response('search_results.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user