Author: thimal
Date: Thu Aug 14 17:18:14 2014
New Revision: 1617996
URL: http://svn.apache.org/r1617996
Log:
added test cases to autocomplete user plugin
added comments to code
Modified:
bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/tests/theme.py
bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/theme.py
Modified:
bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/tests/theme.py
URL:
http://svn.apache.org/viewvc/bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/tests/theme.py?rev=1617996&r1=1617995&r2=1617996&view=diff
==============================================================================
---
bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/tests/theme.py
(original)
+++
bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/tests/theme.py
Thu Aug 14 17:18:14 2014
@@ -63,18 +63,33 @@ class ThemeTestCase(unittest.TestCase):
for dir in self.bhtheme.get_templates_dirs():
self.assertIn(dir, chrome.get_all_templates_dirs())
+ def test_get_users(self):
+
+ self.req.args['term'] = 'us'
+ self.env.known_users = [['user1', 'test', '[email protected]'], ['test',
'user2', '[email protected]'],
+ ['test', 'test', '[email protected]'], ['test',
'test', '[email protected]']]
+ #output need to sort in the user, name, email order
+ # ( where user has the search term it has order 0,
+ # name has search term it has order 1 or if email has search term
order 2
+ test_users = [(0, ['user1', 'test', '[email protected]']), (1, ['test',
'user2', '[email protected]']),
+ (2, ['test', 'test', '[email protected]'])]
+ users = self.autocompleteuser_component._get_users(self.req)
+ self.assertEqual(test_users, users)
+
def test_get_groups(self):
self.req.args['term'] = 'de'
- test_users = [u'dev']
+ self.env.known_users = [['deave', 'deave', '[email protected]']]
+ test_groups = [u'dev'] # groups need have only the groups and not
users
self.env.db_transaction.executemany(
"INSERT INTO permission VALUES (%s,%s)",
[('dev', 'WIKI_MODIFY'),
('dev', 'REPORT_ADMIN'),
- ('admin', 'REPORT_ADMIN')])
- gona=self.env.get_known_users()
- users = self.autocompleteuser_component._get_groups(self.req)
- self.assertEqual(test_users, users)
+ ('admin', 'REPORT_ADMIN'),
+ ('deave', 'REPORT_ADMIN')])
+
+ groups = self.autocompleteuser_component._get_groups(self.req)
+ self.assertEqual(test_groups, groups)
def test_get_keywords_string(self):
test_keywords = ['key1', 'key2', 'key3']
Modified:
bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/theme.py
URL:
http://svn.apache.org/viewvc/bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/theme.py?rev=1617996&r1=1617995&r2=1617996&view=diff
==============================================================================
---
bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/theme.py
(original)
+++
bloodhound/branches/bep_0013_dynamic_clientside_features/bloodhound_theme/bhtheme/theme.py
Thu Aug 14 17:18:14 2014
@@ -745,11 +745,11 @@ class AutocompleteUsers(Component):
def filter_stream(self, req, method, filename, stream, data):
"""add the autocomplete jQuery function to the ticket and permission
pages
"""
- if filename == 'bh_ticket.html':
- fields = [field['name'] for field in data['ticket'].fields
- if field['type'] == 'select']
- fields = set(sum([fnmatch.filter(fields, pattern)
- for pattern in self.select_fields], []))
+ # if filename == 'bh_ticket.html':
+ # fields = [field['name'] for field in data['ticket'].fields
+ # if field['type'] == 'select']
+ # fields = set(sum([fnmatch.filter(fields, pattern)
+ # for pattern in self.select_fields], []))
if filename == 'bh_ticket.html':
@@ -760,6 +760,7 @@ class AutocompleteUsers(Component):
elif filename == 'bh_admin_perms.html':
users = self._get_users(req)
+ # subjects are put into a dictionary so in javascript show all
user, email and name and use only the username
subjects = [{"label": "%s %s %s" % (user[USER] and '%s' %
user[USER] or '', user[EMAIL] and
'<%s>' % user[EMAIL] or '',
user[NAME] and '%s' % user[NAME] or
''), "value":"%s" %
user[USER]} for value, user in users]
@@ -808,7 +809,7 @@ class AutocompleteUsers(Component):
for user_data in self.env.get_known_users():
user_data = [user is not None and
Chrome(self.env).format_author(req, user) or ''
for user in user_data]
- for index, field in enumerate((USER, EMAIL, NAME)): # ordered by
how they appear
+ for index, field in enumerate((EMAIL, NAME, USER)): # ordered by
how they appear
value = user_data[field].lower()
if value.startswith(query):
@@ -862,6 +863,9 @@ class KeywordSuggestModule(Component):
keywords = []
if filename == 'bh_ticket.html':
+ # currently use the inline javascript adding as
+ # it will not if use separate js fills to keywords suggest in
ticket page
+ # Latter need to change to add to a separate js file the following.
# add_script(req, 'theme/js/keywordsuggest_ticket.js')
if req.path_info.startswith('/ticket/'):
js = """
@@ -870,6 +874,7 @@ class KeywordSuggestModule(Component):
var keywords = %(keywords)s
$('%(field)s').tagsinput({
typeahead: {
+ minLength: 0,
source: keywords
}
});
@@ -882,6 +887,7 @@ class KeywordSuggestModule(Component):
$('%(field)s').tagsinput({
typeahead: {
+ minLength: 0,
source: keywords
}
});
@@ -906,12 +912,11 @@ class KeywordSuggestModule(Component):
def _get_keywords_string(self, req):
"""return a list of keywords relevant to the product in the frequency
of usage
"""
- #currently all the keywords are taken through the db query and then
sort them according to there frequency
- # get keywords from db
+ # currently all the keywords are taken through the db query and then
sort them according to there frequency
keywords = []
with self.env.db_direct_query as db:
cursor = db.cursor()
-
+ # find the product and get the sql where clause. If not in product
environment get a empty string
if self.env.product is not None:
product = self.env.product._data['prefix']
product_sql = " AND t.product = '%s'" % product
@@ -944,9 +949,11 @@ class DuplicateTicketSearch(Component):
implements(ITemplateStreamFilter, IRequestHandler)
# ITemplateStreamFilter methods
-
def filter_stream(self, req, method, filename, stream, data):
-
+ """add the jQuery and javascript functions which need to show
duplicate tickets
+ to all the pages which has the create ticket capability
+ """
+ # javascript for popup
add_script(req, 'theme/js/popoverDupSearch.js')
if filename == 'bh_ticket.html':
@@ -959,12 +966,15 @@ class DuplicateTicketSearch(Component):
# IRequestHandler methods
def match_request(self, req):
- """Handle requests sent to /user_list and /ticket/user_list
+ """Handle requests sent to */duplicate_ticket_search
+ (this can be ticket page or any other page)
"""
return re.match('.*/duplicate_ticket_search$', req.path_info)
def process_request(self, req):
-
+ """find and send the potential duplicate ticket data (summary,
description, type, status, author, date, ticket
+ id (to get ticket url)) in JSON format.
+ """
terms = self._terms_to_search(req)
term_split = req.args.get('q').split(' ')
@@ -972,12 +982,18 @@ class DuplicateTicketSearch(Component):
sql, args = self._sql_to_search(db, ['summary', 'keywords',
'description'], terms)
sql2, args2 = self._sql_to_search(db, ['newvalue'], terms)
sql3, args3 = self._sql_to_search(db, ['value'], terms)
+
+ # find the product and return sql where clause to find related to
product
+ # if not in a product environment return empty string
if self.env.product is not None:
product_sql = "product='%s' AND" %
self.env.product._data['prefix']
else:
product_sql = ""
+
ticket_list = []
ticket_list_value = []
+
+ # search tickets from ticket,ticket_change, and ticket_custom
tables.
for summary, desc, author, type, tid, ts, status, resolution in \
db("""SELECT summary, description, reporter, type, id,
time, status, resolution
@@ -995,13 +1011,15 @@ class DuplicateTicketSearch(Component):
summary_term_count = 0
summary_list = summary.split(' ')
+
+ # find the matched terms and highlight them
for s in summary_list:
for t in term_split:
if s.lower() == t.lower():
summary = summary.replace(s, '<em>'+t+'</em>')
summary_term_count += 1
break
-
+ # convert searched tickets to JSON objects
ticket_list.append(to_json({'summary': summary, 'description':
desc, 'type': type, 'status': status,
'owner': author, 'date':
user_time(req, format_datetime, ts), 'url': tid}))
ticket_list_value.append(summary_term_count)
@@ -1019,7 +1037,7 @@ class DuplicateTicketSearch(Component):
The result is returned as an `(sql, params)` tuple.
"""
assert columns and terms
-
+ # this is taken from the trac search to get sql where clauses
likes = ['%s %s' % (i, db.like()) for i in columns]
c = ' OR '.join(likes)
sql = '(' + ') OR ('.join([c] * len(terms)) + ')'
@@ -1033,15 +1051,20 @@ class DuplicateTicketSearch(Component):
The result is returned as a list of terms.
"""
+ # currently search terms are find removing one word at time until 3
words remain.
+ # This seem to give the best result so far, but need to change this to
advance method
+ # It may possible to use Solr search to replace this
search_string = req.args.get('q')
terms = [search_string]
temp_string = search_string
search_string_split = search_string.split(' ')
+ # remove elements form beginning of the search term
for i in range(len(search_string_split)-3):
search_string = re.sub('^'+search_string_split[i]+' ', '',
search_string)
terms.append(search_string)
search_string = temp_string
+ # remove elements form ene of the search term
for i in reversed(xrange(3, len(search_string_split))):
search_string = re.sub(' '+search_string_split[i]+'$', '',
search_string)
terms.append(search_string)