[open-ils-commits] r67 - servres/trunk/conifer/syrup
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Dec 1 12:00:56 EST 2008
Author: artunit
Date: 2008-12-01 12:00:54 -0500 (Mon, 01 Dec 2008)
New Revision: 67
Modified:
servres/trunk/conifer/syrup/models.py
servres/trunk/conifer/syrup/views.py
Log:
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2008-11-28 21:13:01 UTC (rev 66)
+++ servres/trunk/conifer/syrup/models.py 2008-12-01 17:00:54 UTC (rev 67)
@@ -159,6 +159,9 @@
default = 'STUDT',
max_length = 5)
+ def instr_name(self):
+ return self.user.last_name
+
def __unicode__(self):
return '%s--%s--%s' % (self.user, self.role, self.course)
Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py 2008-11-28 21:13:01 UTC (rev 66)
+++ servres/trunk/conifer/syrup/views.py 2008-12-01 17:00:54 UTC (rev 67)
@@ -9,6 +9,7 @@
import re
from django.db.models import Q
+
#------------------------------------------------------------
def auth_handler(request, path):
@@ -139,6 +140,24 @@
query = query & or_query
return query
+#------------------------------------------------------------
+
+def highlight(text, phrase,
+ highlighter='<strong class="highlight">\\1</strong>'):
+ ''' This may be a lame way to do this, but will want to highlight matches somehow
+
+ >>> highlight('The River is Wide', 'wide')
+ 'The River is <strong class="highlight">Wide</strong>'
+
+ '''
+ if not phrase or not text:
+ return text
+ highlight_re = re.compile('(%s)' % re.escape(phrase), re.I)
+ if hasattr(text, '__html__'):
+ return literal(highlight_re.sub(highlighter, text))
+ else:
+ return highlight_re.sub(highlighter, text)
+
def search(request):
''' Need to work on this
@@ -149,11 +168,17 @@
count = int(request.GET.get('count', 5))
if ('q' in request.GET) and request.GET['q'].strip():
query_string = request.GET['q']
+ norm_query = normalize_query(query_string)
entry_query = get_query(query_string, ['title', 'author', 'course__title', 'course__department__name'])
instr_query = get_query(query_string, ['user__last_name'])
paginator = Paginator( models.Item.objects.filter(entry_query).order_by('-date_created'),
count)
- instructor_list = models.Member.objects.filter(instr_query).filter(role='INSTR').order_by('-user__last_name')
+ instructor_list = models.Member.objects.filter(instr_query).filter(role='INSTR').order_by('-user__last_name')[0:5]
+ print(norm_query)
+ for term in norm_query:
+ print term
+ print len(models.Member.objects.filter(instr_query).filter(role='INSTR'))
+ print highlight('The River Is Wide', 'is wide')
return g.render('search_results.xhtml', paginator=paginator,
page_num=page_num,
More information about the open-ils-commits
mailing list