Added new setting: side bar search box

This commit is contained in:
Roberto Rosario
2011-03-10 01:54:31 -04:00
parent ed5578832f
commit 6bef320142
16 changed files with 157 additions and 22 deletions

View File

@@ -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},
])

View File

@@ -1,22 +1,19 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n %} {% load i18n %}
{% block title %} :: {% trans "Search results" %}{% endblock %} {% block title %} :: {% trans "Search results" %}{% endblock %}
{% block content %}
{% with "get" as submit_method %} {% block content %}
{% with form_title as title %} {% if form %}
{% include "generic_form_subtemplate.html" %} {% include "search_results_subtemplate.html" %}
{% endwith %} {% endif %}
{% endwith %}
{% if query_string %} {% if query_string %}
{% include "generic_list_subtemplate.html" %} {% include "generic_list_subtemplate.html" %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block footer %} {% block footer %}
{% if query_string %} {% if query_string %}
{% blocktrans %}Elapsed time: {{ time_delta }} seconds{% endblocktrans %} {% blocktrans %}Elapsed time: {{ time_delta }} seconds{% endblocktrans %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@@ -0,0 +1,5 @@
{% with "get" as submit_method %}
{% with form_title as title %}
{% include "generic_form_subtemplate.html" %}
{% endwith %}
{% endwith %}

View 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

View File

@@ -3,6 +3,7 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('dynamic_search.views', urlpatterns = patterns('dynamic_search.views',
url(r'^search/$', 'search', (), 'search'), url(r'^search/$', 'search', (), 'search'),
url(r'^results/$', 'results', (), 'results'),
) )

View File

@@ -10,6 +10,57 @@ from forms import SearchForm
from conf.settings import SHOW_OBJECT_TYPE 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): def search(request):
query_string = '' query_string = ''
context = {} context = {}
@@ -52,3 +103,4 @@ def search(request):
return render_to_response('search_results.html', context, return render_to_response('search_results.html', context,
context_instance=RequestContext(request)) context_instance=RequestContext(request))
"""

View File

@@ -7,12 +7,12 @@ from permissions import role_list
from documents import document_find_all_duplicates from documents import document_find_all_duplicates
from filesystem_serving import filesystem_serving_recreate_all_links 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'} check_settings = {'text':_(u'settings'), 'view':'check_settings', 'famfam':'cog'}
main_menu = [
register_menu([
{'text':_(u'home'), 'view':'home', 'famfam':'house', 'position':0}, {'text':_(u'home'), 'view':'home', 'famfam':'house', 'position':0},
{'text':_(u'tools'), 'view':'tools_menu', 'links': [ {'text':_(u'tools'), 'view':'tools_menu', 'links': [
document_find_all_duplicates, filesystem_serving_recreate_all_links document_find_all_duplicates, filesystem_serving_recreate_all_links
],'famfam':'wrench', 'name':'tools','position':7}, ],'famfam':'wrench', 'name':'tools','position':7},
@@ -22,4 +22,10 @@ register_menu([
],'famfam':'cog', 'name':'setup','position':8}, ],'famfam':'cog', 'name':'setup','position':8},
{'text':_(u'about'), 'view':'about', 'position':9}, {'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)

View File

View File

@@ -0,0 +1,4 @@
from django.conf import settings
SIDE_BAR_SEARCH = getattr(settings, 'MAIN_SIDE_BAR_SEARCH', False)

View File

@@ -3,6 +3,8 @@
{% load project_tags %} {% load project_tags %}
{% load navigation %} {% load navigation %}
{% load settings %} {% load settings %}
{% load search_tags %}
{% load main_settings_tags %}
{% block html_title %}{% project_name %}{% block title %}{% endblock %}{% endblock %} {% block html_title %}{% project_name %}{% block title %}{% endblock %}{% endblock %}
@@ -118,6 +120,13 @@
{% endblock %} {% endblock %}
{% block web_theme_sidebar %} {% 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 %} {% get_object_navigation_links %}
{% if object_navigation_links %} {% if object_navigation_links %}
<div class="block"> <div class="block">

View File

View 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)

View File

@@ -1,3 +1,6 @@
2011-Mar-10
* Added new setting: side bar search box
2011-Mar-09 2011-Mar-09
* Implemented new PermissioDenied exception middleware handler * Implemented new PermissioDenied exception middleware handler
* Permissions app api now returns a PermissionDenied exception instead of a custom one * Permissions app api now returns a PermissionDenied exception instead of a custom one
@@ -14,6 +17,9 @@
* Show sentry login for admin users * Show sentry login for admin users
* Do not reinitialize document queue and/or queued document on reentry * Do not reinitialize document queue and/or queued document on reentry
* Try extra hard not to assign same uuid to two documents * Try extra hard not to assign same uuid to two documents
* Added new transformation preview size setting
* Renamed document queue state links
* Changed ocr status display sidebar from form based to text based
2011-Mar-08 2011-Mar-08
* Added document action to clear all the document's page transformations * Added document action to clear all the document's page transformations

View File

@@ -47,7 +47,11 @@ TODO, WISHLIST
* Show current page in generic list template - DONE * Show current page in generic list template - DONE
* Enable/disable ocr queue view & links - DONE * Enable/disable ocr queue view & links - DONE
Main
====
* Diagnostics (document file <-> document db entry mismatches, orphan files) * Diagnostics (document file <-> document db entry mismatches, orphan files)
* Sidebar search - DONE
Common Common
====== ======
@@ -70,7 +74,6 @@ Permissions
Documents Documents
========= =========
* Restrict view permission free form rename
* Skip step 2 of wizard (metadata) if no document type metadata types have been defined * Skip step 2 of wizard (metadata) if no document type metadata types have been defined
* Tile based image server * Tile based image server
* Do separate default transformations for staging and for local uploads * Do separate default transformations for staging and for local uploads
@@ -103,6 +106,7 @@ Documents
* Improve doc page template/view * Improve doc page template/view
* Document page edit view * Document page edit view
* Show all document's pages content combined * Show all document's pages content combined
* Create 'simple view' = stripped down document view for non technical users
Filesystem serving Filesystem serving
================== ==================
@@ -116,7 +120,7 @@ Search
* Add show_summary method to model to display as results of a search * Add show_summary method to model to display as results of a search
* Cross model inclusion search - DONE * Cross model inclusion search - DONE
* Separate view code from search code - DONE * Separate view code from search code - DONE
* Sidebar search * New results only view - DONE
Convert Convert
======= =======

View File

@@ -177,6 +177,8 @@ LOGIN_EXEMPT_URLS = (
#PAGINATION_DEFAULT_PAGINATION = 10 #PAGINATION_DEFAULT_PAGINATION = 10
#--------- Web theme app --------------- #--------- Web theme app ---------------
#WEB_THEME = 'default' #WEB_THEME = 'default'
#-------------- Main -----------------
#MAIN_SIDE_BAR_SEARCH = False
#---------- Documents ------------------ #---------- Documents ------------------
# Definition # Definition
#DOCUMENTS_METADATA_AVAILABLE_FUNCTIONS = {} #DOCUMENTS_METADATA_AVAILABLE_FUNCTIONS = {}
@@ -243,7 +245,6 @@ LOGIN_EXEMPT_URLS = (
#OCR_MAX_CONCURRENT_EXECUTION = 2 #OCR_MAX_CONCURRENT_EXECUTION = 2
#OCR_TESSERACT_LANGUAGE = None #OCR_TESSERACT_LANGUAGE = None
# Permissions # Permissions
#ROLES_DEFAULT_ROLES = [] #ROLES_DEFAULT_ROLES = []