Change sites vocabulary to display titles instead of registered names
authorThierry Florac <thierry.florac@onf.fr>
Fri, 08 Jul 2016 15:35:48 +0200
changeset 50 06c4fcde82bc
parent 49 393b306a69db
child 51 5f6b98be4c04
Change sites vocabulary to display titles instead of registered names
src/pyams_content/shared/site/__init__.py
--- a/src/pyams_content/shared/site/__init__.py	Fri Jun 24 16:28:12 2016 +0200
+++ b/src/pyams_content/shared/site/__init__.py	Fri Jul 08 15:35:48 2016 +0200
@@ -17,13 +17,15 @@
 
 # import interfaces
 from pyams_content.shared.common.interfaces import ISharedSite
+from pyams_i18n.interfaces import II18n
 from zope.schema.interfaces import IVocabularyFactory
 
 # import packages
 from pyams_utils.container import BTreeOrderedContainer
-from zope.componentvocabulary.vocabulary import UtilityVocabulary
+from pyams_utils.registry import get_utilities_for
+from pyams_utils.request import query_request
 from zope.interface import provider, implementer
-from zope.schema.vocabulary import getVocabularyRegistry
+from zope.schema.vocabulary import getVocabularyRegistry, SimpleTerm, SimpleVocabulary
 
 
 @implementer(ISharedSite)
@@ -32,10 +34,15 @@
 
 
 @provider(IVocabularyFactory)
-class SharedSiteVocabulary(UtilityVocabulary):
+class SharedSiteVocabulary(SimpleVocabulary):
     """Shared sites vocabulary"""
 
     interface = ISharedSite
-    nameOnly = True
+
+    def __init__(self, context):
+        request = query_request()
+        super(SharedSiteVocabulary, self).__init__([SimpleTerm(v, title=II18n(t).query_attribute('title',
+                                                                                                 request=request))
+                                                    for v, t in get_utilities_for(self.interface)])
 
 getVocabularyRegistry().register('PyAMS shared sites', SharedSiteVocabulary)