From 02a0a792ee0f54d9456aced7f955cb6dfe3f30cf Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Fri, 30 Aug 2013 18:11:22 +0200 Subject: [PATCH] Check do_post_sort attribute on source to be able to disable the sorting. --- CHANGES.rst | 2 ++ src/collective/contact/widget/widgets.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9c5654b..323eec6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,8 @@ Changelog 1.0 (unreleased) ---------------- +- Check do_post_sort attribute on source to be able to disable the sorting. + - Declare dependencies on z3c.relationfield and plone.formwidget.contenttree. - Remove ploneform-render-widget view for content provider, this is now diff --git a/src/collective/contact/widget/widgets.py b/src/collective/contact/widget/widgets.py index ed4d552..e41bcbc 100644 --- a/src/collective/contact/widget/widgets.py +++ b/src/collective/contact/widget/widgets.py @@ -279,9 +279,12 @@ class AutocompleteSearch(BaseAutocompleteSearch): query = "path:%s %s" % (source.tokenToPath(path), query) if query: - terms = set(source.search(query)) + terms = source.search(query) else: - terms = set() + terms = () + + if getattr(source, 'do_post_sort', True): + terms = sorted(set(terms), key=lambda t: t.title) return u'\n'.join([u"|".join((t.token, t.title or t.token, t.portal_type, t.url, t.extra)) - for t in sorted(terms, key=lambda t: t.title)]) + for t in terms])