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))
|
||||
"""
|
||||
|
||||
@@ -7,12 +7,12 @@ from permissions import role_list
|
||||
from documents import document_find_all_duplicates
|
||||
from filesystem_serving import filesystem_serving_recreate_all_links
|
||||
|
||||
from main.conf.settings import SIDE_BAR_SEARCH
|
||||
|
||||
check_settings = {'text':_(u'settings'), 'view':'check_settings', 'famfam':'cog'}
|
||||
|
||||
|
||||
register_menu([
|
||||
main_menu = [
|
||||
{'text':_(u'home'), 'view':'home', 'famfam':'house', 'position':0},
|
||||
|
||||
{'text':_(u'tools'), 'view':'tools_menu', 'links': [
|
||||
document_find_all_duplicates, filesystem_serving_recreate_all_links
|
||||
],'famfam':'wrench', 'name':'tools','position':7},
|
||||
@@ -22,4 +22,10 @@ register_menu([
|
||||
],'famfam':'cog', 'name':'setup','position':8},
|
||||
|
||||
{'text':_(u'about'), 'view':'about', 'position':9},
|
||||
])
|
||||
]
|
||||
|
||||
if not SIDE_BAR_SEARCH:
|
||||
main_menu.insert(1, {'text':_(u'search'), 'view':'search', 'famfam':'zoom', 'position':2})
|
||||
|
||||
register_menu(main_menu)
|
||||
|
||||
|
||||
0
apps/main/conf/__init__.py
Normal file
0
apps/main/conf/__init__.py
Normal file
4
apps/main/conf/settings.py
Normal file
4
apps/main/conf/settings.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from django.conf import settings
|
||||
|
||||
SIDE_BAR_SEARCH = getattr(settings, 'MAIN_SIDE_BAR_SEARCH', False)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
{% load project_tags %}
|
||||
{% load navigation %}
|
||||
{% load settings %}
|
||||
{% load search_tags %}
|
||||
{% load main_settings_tags %}
|
||||
|
||||
{% block html_title %}{% project_name %}{% block title %}{% endblock %}{% endblock %}
|
||||
|
||||
@@ -118,6 +120,13 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block web_theme_sidebar %}
|
||||
{% get_main_setting "SIDE_BAR_SEARCH" as side_bar_search %}
|
||||
{% if side_bar_search %}
|
||||
{% with "true" as side_bar %}
|
||||
{% search_form %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% get_object_navigation_links %}
|
||||
{% if object_navigation_links %}
|
||||
<div class="block">
|
||||
|
||||
0
apps/main/templatetags/__init__.py
Normal file
0
apps/main/templatetags/__init__.py
Normal file
35
apps/main/templatetags/main_settings_tags.py
Normal file
35
apps/main/templatetags/main_settings_tags.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import re
|
||||
|
||||
from django.template import Node, Variable
|
||||
from django.template import TemplateSyntaxError, Library, VariableDoesNotExist
|
||||
from django.template.defaultfilters import stringfilter
|
||||
from django.template.defaultfilters import date as datefilter
|
||||
from main.conf import settings
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
class SettingsNode(Node):
|
||||
def __init__(self, format_string, var_name):
|
||||
self.format_string = format_string
|
||||
self.var_name = var_name
|
||||
def render(self, context):
|
||||
context[self.var_name] = getattr(settings, self.format_string, '')
|
||||
return ''
|
||||
|
||||
|
||||
@register.tag
|
||||
def get_main_setting(parser, token):
|
||||
# This version uses a regular expression to parse tag contents.
|
||||
try:
|
||||
# Splitting by None == splitting by spaces.
|
||||
tag_name, arg = token.contents.split(None, 1)
|
||||
except ValueError:
|
||||
raise TemplateSyntaxError, "%r tag requires arguments" % token.contents.split()[0]
|
||||
m = re.search(r'(.*?) as (\w+)', arg)
|
||||
if not m:
|
||||
raise TemplateSyntaxError, "%r tag had invalid arguments" % tag_name
|
||||
format_string, var_name = m.groups()
|
||||
if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")):
|
||||
raise TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name
|
||||
return SettingsNode(format_string[1:-1], var_name)
|
||||
Reference in New Issue
Block a user