Changed vocabulary declaration
authorThierry Florac <thierry.florac@onf.fr>
Tue, 15 Nov 2016 09:47:14 +0100
changeset 60 da1454d7d358
parent 59 6da36451e36b
child 61 e5d6ea4dc839
Changed vocabulary declaration
src/pyams_content/component/extfile/__init__.py
src/pyams_content/component/extfile/container.py
src/pyams_content/component/gallery/container.py
src/pyams_content/component/links/container.py
src/pyams_content/component/paragraph/illustration.py
src/pyams_content/shared/news/__init__.py
src/pyams_content/shared/site/__init__.py
--- a/src/pyams_content/component/extfile/__init__.py	Mon Oct 24 15:54:38 2016 +0200
+++ b/src/pyams_content/component/extfile/__init__.py	Tue Nov 15 09:47:14 2016 +0100
@@ -20,20 +20,20 @@
 from pyams_content.shared.common.interfaces import IWfSharedContent
 from pyams_form.interfaces.form import IFormContextPermissionChecker
 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent, IObjectRemovedEvent
-from zope.schema.interfaces import IVocabularyFactory
 
 # import packages
 from persistent import Persistent
 from pyams_i18n.property import I18nFileProperty
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.traversing import get_parent
+from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
 from pyramid.threadlocal import get_current_registry
 from zope.container.contained import Contained
-from zope.interface import implementer, provider
+from zope.interface import implementer
 from zope.lifecycleevent import ObjectModifiedEvent
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm, getVocabularyRegistry
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 from pyams_content import _
 
@@ -47,7 +47,7 @@
         EXTERNAL_FILES_FACTORIES[key] = (factory, name or key)
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS files factories')
 class ExternalFilesFactoriesVocabulary(SimpleVocabulary):
     """External files factories vocabulary"""
 
@@ -56,8 +56,6 @@
                        key=lambda x: x.title)
         super(ExternalFilesFactoriesVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS files factories', ExternalFilesFactoriesVocabulary)
-
 
 @implementer(IBaseExtFile)
 class BaseExtFile(Persistent, Contained):
--- a/src/pyams_content/component/extfile/container.py	Mon Oct 24 15:54:38 2016 +0200
+++ b/src/pyams_content/component/extfile/container.py	Tue Nov 15 09:47:14 2016 +0100
@@ -22,7 +22,6 @@
 from pyams_i18n.interfaces import II18n
 from zope.annotation.interfaces import IAnnotations
 from zope.location.interfaces import ISublocations
-from zope.schema.interfaces import IVocabularyFactory
 from zope.traversing.interfaces import ITraversable
 
 # import packages
@@ -30,13 +29,14 @@
 from persistent.list import PersistentList
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.traversing import get_parent
+from pyams_utils.vocabulary import vocabulary_config
 from pyramid.threadlocal import get_current_registry
 from zope.container.contained import Contained
 from zope.container.folder import Folder
-from zope.interface import implementer, provider
+from zope.interface import implementer
 from zope.lifecycleevent import ObjectCreatedEvent
 from zope.location import locate
-from zope.schema.vocabulary import SimpleVocabulary, getVocabularyRegistry, SimpleTerm
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
 #
@@ -103,7 +103,7 @@
         return IExtFileContainer(self.context).values()
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS content external files')
 class ExtFileContainerFilesVocabulary(SimpleVocabulary):
     """External files container files vocabulary"""
 
@@ -113,8 +113,6 @@
                  for file in IExtFileContainer(target).values()]
         super(ExtFileContainerFilesVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS content external files', ExtFileContainerFilesVocabulary)
-
 
 #
 # External file links container
--- a/src/pyams_content/component/gallery/container.py	Mon Oct 24 15:54:38 2016 +0200
+++ b/src/pyams_content/component/gallery/container.py	Tue Nov 15 09:47:14 2016 +0100
@@ -20,7 +20,6 @@
     GALLERY_CONTAINER_KEY, IGalleryLinksContainer, IGalleryLinksContainerTarget, GALLERY_LINKS_CONTAINER_KEY
 from zope.annotation.interfaces import IAnnotations
 from zope.location.interfaces import ISublocations
-from zope.schema.interfaces import IVocabularyFactory
 from zope.traversing.interfaces import ITraversable
 
 # import packages
@@ -29,13 +28,14 @@
 from pyams_i18n.interfaces import II18n
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.traversing import get_parent
+from pyams_utils.vocabulary import vocabulary_config
 from pyramid.threadlocal import get_current_registry
 from zope.container.contained import Contained
 from zope.container.folder import Folder
-from zope.interface import implementer, provider
+from zope.interface import implementer
 from zope.lifecycleevent import ObjectCreatedEvent
 from zope.location import locate
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm, getVocabularyRegistry
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
 #
@@ -82,7 +82,7 @@
         return IGalleryContainer(self.context).values()
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS content galleries')
 class GalleryContainerGalleriesVocabulary(SimpleVocabulary):
     """Galleries container galleries vocabulary"""
 
@@ -92,8 +92,6 @@
                  for gallery in IGalleryContainer(target).values()]
         super(GalleryContainerGalleriesVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS content galleries', GalleryContainerGalleriesVocabulary)
-
 
 #
 # Galleries links container
--- a/src/pyams_content/component/links/container.py	Mon Oct 24 15:54:38 2016 +0200
+++ b/src/pyams_content/component/links/container.py	Tue Nov 15 09:47:14 2016 +0100
@@ -21,7 +21,6 @@
 from pyams_i18n.interfaces import II18n
 from zope.annotation.interfaces import IAnnotations
 from zope.location.interfaces import ISublocations
-from zope.schema.interfaces import IVocabularyFactory
 from zope.traversing.interfaces import ITraversable
 
 # import packages
@@ -29,13 +28,14 @@
 from persistent.list import PersistentList
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.traversing import get_parent
+from pyams_utils.vocabulary import vocabulary_config
 from pyramid.threadlocal import get_current_registry
 from zope.container.contained import Contained
 from zope.container.folder import Folder
-from zope.interface import implementer, provider
+from zope.interface import implementer
 from zope.lifecycleevent import ObjectCreatedEvent
 from zope.location import locate
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm, getVocabularyRegistry
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
 @implementer(ILinkContainer)
@@ -78,7 +78,7 @@
         return ILinkContainer(self.context).values()
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS content links')
 class LinkContainerLinksVocabulary(SimpleVocabulary):
     """Links container links vocabulary"""
 
@@ -88,8 +88,6 @@
                  for link in ILinkContainer(target).values()]
         super(LinkContainerLinksVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS content links', LinkContainerLinksVocabulary)
-
 
 #
 # Link links container
--- a/src/pyams_content/component/paragraph/illustration.py	Mon Oct 24 15:54:38 2016 +0200
+++ b/src/pyams_content/component/paragraph/illustration.py	Tue Nov 15 09:47:14 2016 +0100
@@ -17,15 +17,16 @@
 
 # import interfaces
 from pyams_content.component.paragraph.interfaces import IIllustrationParagraph, IIllustrationRenderer
-from zope.schema.interfaces import IVocabularyFactory
+from pyams_file.interfaces import DELETED_FILE, IResponsiveImage
 
 # import packages
 from pyams_content.component.paragraph import BaseParagraph
 from pyams_file.property import FileProperty
 from pyams_utils.request import check_request
-from zope.interface import implementer, provider
+from pyams_utils.vocabulary import vocabulary_config
+from zope.interface import implementer, alsoProvides
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import getVocabularyRegistry, SimpleVocabulary, SimpleTerm
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
 #
@@ -36,12 +37,22 @@
 class Illustration(BaseParagraph):
     """Illustration class"""
 
-    data = FileProperty(IIllustrationParagraph['data'])
+    _data = FileProperty(IIllustrationParagraph['data'])
     legend = FieldProperty(IIllustrationParagraph['legend'])
     renderer = FieldProperty(IIllustrationParagraph['renderer'])
 
+    @property
+    def data(self):
+        return self._data
 
-@provider(IVocabularyFactory)
+    @data.setter
+    def data(self, value):
+        self._data = value
+        if (value is not None) and (value is not DELETED_FILE):
+            alsoProvides(self._data, IResponsiveImage)
+
+
+@vocabulary_config(name='PyAMS illustration renderers')
 class IllustrationRendererVocabulary(SimpleVocabulary):
     """Illustration renderer utilities vocabulary"""
 
@@ -54,5 +65,3 @@
                  for name, adapter in sorted(registry.getAdapters((context, request), IIllustrationRenderer),
                                              key=lambda x: x[1].weight)]
         super(IllustrationRendererVocabulary, self).__init__(terms)
-
-getVocabularyRegistry().register('PyAMS illustration renderers', IllustrationRendererVocabulary)
--- a/src/pyams_content/shared/news/__init__.py	Mon Oct 24 15:54:38 2016 +0200
+++ b/src/pyams_content/shared/news/__init__.py	Tue Nov 15 09:47:14 2016 +0100
@@ -24,18 +24,18 @@
 from pyams_content.shared.news.interfaces import INewsEvent, IWfNewsEvent, NEWS_CONTENT_TYPE, NEWS_CONTENT_NAME, \
     DISPLAY_FIRST_VERSION, DISPLAY_CURRENT_VERSION, VERSION_DISPLAY
 from pyams_workflow.interfaces import IWorkflowVersions, VersionError, IWorkflowPublicationInfo
-from zope.schema.interfaces import IVocabularyFactory
 
 # import packages
 from pyams_content.shared.common import SharedContent, WfSharedContent, register_content_type
 from pyams_utils.date import format_date
 from pyams_utils.request import check_request
-from zope.interface import implementer, provider
+from pyams_utils.vocabulary import vocabulary_config
+from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm, getVocabularyRegistry
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS news publication date')
 class WfNewsDisplayedDateVocabulary(SimpleVocabulary):
     """Base news event vocabulary"""
 
@@ -64,8 +64,6 @@
         terms.append(SimpleTerm(DISPLAY_CURRENT_VERSION, title=current_version_label))
         super(WfNewsDisplayedDateVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS news publication date', WfNewsDisplayedDateVocabulary)
-
 
 @implementer(IWfNewsEvent, IParagraphContainerTarget, IThemesTarget, IExtFileContainerTarget, ILinkContainerTarget,
              IGalleryContainerTarget)
--- a/src/pyams_content/shared/site/__init__.py	Mon Oct 24 15:54:38 2016 +0200
+++ b/src/pyams_content/shared/site/__init__.py	Tue Nov 15 09:47:14 2016 +0100
@@ -18,14 +18,14 @@
 # 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 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, SimpleTerm, SimpleVocabulary
+from pyams_utils.vocabulary import vocabulary_config
+from zope.interface import implementer
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
 
 
 @implementer(ISharedSite)
@@ -33,7 +33,7 @@
     """Shared site persistent class"""
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS shared sites')
 class SharedSiteVocabulary(SimpleVocabulary):
     """Shared sites vocabulary"""
 
@@ -44,5 +44,3 @@
         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)