summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Fretin <vincent.fretin@gmail.com>2013-08-30 16:11:22 (GMT)
committerVincent Fretin <vincent.fretin@gmail.com>2013-08-30 16:11:22 (GMT)
commit02a0a792ee0f54d9456aced7f955cb6dfe3f30cf (patch)
treed2892d6075121eeca1ec36f072d6ed3eac33413b
parent4b42da9439d2303779e8fb84eba3ef523c30b681 (diff)
downloadcollective.contact.widget-02a0a792ee0f54d9456aced7f955cb6dfe3f30cf.zip
collective.contact.widget-02a0a792ee0f54d9456aced7f955cb6dfe3f30cf.tar.gz
collective.contact.widget-02a0a792ee0f54d9456aced7f955cb6dfe3f30cf.tar.bz2
Check do_post_sort attribute on source to be able to disable the sorting.
-rw-r--r--CHANGES.rst2
-rw-r--r--src/collective/contact/widget/widgets.py9
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])