[open-ils-commits] r68 - servres/trunk/conifer/syrup
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Dec 1 14:01:23 EST 2008
Author: artunit
Date: 2008-12-01 14:01:20 -0500 (Mon, 01 Dec 2008)
New Revision: 68
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-12-01 17:00:54 UTC (rev 67)
+++ servres/trunk/conifer/syrup/models.py 2008-12-01 19:01:20 UTC (rev 68)
@@ -2,7 +2,25 @@
from django.contrib.auth.models import User
from django.contrib.auth.models import AnonymousUser
from datetime import datetime
+import re
+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)
+
+
#----------------------------------------------------------------------
# USERS
@@ -159,6 +177,14 @@
default = 'STUDT',
max_length = 5)
+ def instr_name_hl(self, terms):
+ for term in terms:
+ hl_instr = highlight(self.user.last_name,term)
+ if not hl_instr == self.user.last_name:
+ return hl_instr
+
+ return self.user.last_name
+
def instr_name(self):
return self.user.last_name
Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py 2008-12-01 17:00:54 UTC (rev 67)
+++ servres/trunk/conifer/syrup/views.py 2008-12-01 19:01:20 UTC (rev 68)
@@ -4,9 +4,9 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login, logout
import conifer.genshi_support as g
+import re
from conifer.syrup import models
from django.contrib.auth.models import User
-import re
from django.db.models import Q
@@ -142,22 +142,6 @@
#------------------------------------------------------------
-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
@@ -178,9 +162,11 @@
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')
+ instr_len = 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,
- count=count, query_string=query_string, instructor_list=instructor_list)
+ count=count, query_string=query_string, instructor_list=instructor_list,
+ norm_query=norm_query, instr_len=instr_len)
More information about the open-ils-commits
mailing list