From b4b792781c80932a24c62d9c914b7ed6a92fd648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 28 Nov 2011 15:09:58 +0100 Subject: [PATCH] more logic in author autocomplete (#1012) --- tabellio/searchform/form.py | 11 ++++++++--- tabellio/searchform/js_macros.pt | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tabellio/searchform/form.py b/tabellio/searchform/form.py index db24903..3890ea9 100644 --- a/tabellio/searchform/form.py +++ b/tabellio/searchform/form.py @@ -78,9 +78,14 @@ class ListAuthorsView(BrowserView): for object in self.deputies_folder.objectValues(): if object.portal_type != 'themis.datatypes.deputy': continue - if q in normalizer.normalize(object.Title()).lower(): - s.append(object) - s.sort() + re.split(r'[-\s]', 'hello-pol to') + for name_part in re.split(r'[-\s]', normalizer.normalize(object.Title()).lower()): + if name_part.startswith(q): + s.append(object) + def cmp_deputy(x, y): + return cmp(normalizer.normalize(x.Title()).lower(), + normalizer.normalize(y.Title()).lower()) + s.sort(cmp_deputy) return '\n'.join(['%s|%s' % (x.Title(), x.id) for x in s]) class ListPolgroupsView(BrowserView): diff --git a/tabellio/searchform/js_macros.pt b/tabellio/searchform/js_macros.pt index aeb70f7..568610d 100644 --- a/tabellio/searchform/js_macros.pt +++ b/tabellio/searchform/js_macros.pt @@ -63,7 +63,7 @@ if(typeof(String.prototype.trim) === "undefined") { (function($) { $().ready(function() { $('.author-autocomplete').each(sync_authors).autocomplete(PORTAL_URL+'/listAuthors', { - }).result(autocomplete_ready); + 'matchContains': true, 'scroll': true, 'max': 30}).result(autocomplete_ready); $('.polgroup-autocomplete').each(sync_polgroups).autocomplete(PORTAL_URL+'/listPolgroups', { }).result(autocomplete_ready); $('.topic-autocomplete').each(sync_topics).autocomplete(PORTAL_URL+'/listTopics', {