src/pyams_content/component/illustration/__init__.py
changeset 555 8e8a14452567
parent 536 1e10e634ec13
child 558 d9c6b1d7fefa
--- a/src/pyams_content/component/illustration/__init__.py	Thu May 24 10:51:45 2018 +0200
+++ b/src/pyams_content/component/illustration/__init__.py	Fri May 25 08:03:41 2018 +0200
@@ -29,9 +29,10 @@
 # import packages
 from persistent import Persistent
 from pyams_content.features.checker import BaseContentChecker
-from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer
+from pyams_content.features.renderer import RenderedContentMixin, RenderersVocabulary
 from pyams_i18n.property import I18nFileProperty
 from pyams_utils.adapter import adapter_config, ContextAdapter
+from pyams_utils.factory import factory_config
 from pyams_utils.registry import query_utility, get_utility
 from pyams_utils.request import check_request
 from pyams_utils.traversing import get_parent
@@ -43,13 +44,13 @@
 from zope.lifecycleevent import ObjectCreatedEvent, ObjectAddedEvent
 from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 from pyams_content import _
 
 
 @implementer(IIllustration)
-class Illustration(Persistent, Contained, RenderedContentMixin):
+@factory_config(provided=IIllustration)
+class Illustration(RenderedContentMixin, Persistent, Contained):
     """Illustration persistent class"""
 
     _data = I18nFileProperty(IIllustration['data'])
@@ -178,16 +179,7 @@
 
 
 @vocabulary_config(name=ILLUSTRATION_RENDERERS)
-class IllustrationRendererVocabulary(SimpleVocabulary):
+class IllustrationRendererVocabulary(RenderersVocabulary):
     """Illustration renderers vocabulary"""
 
-    def __init__(self, context=None):
-        request = check_request()
-        translate = request.localizer.translate
-        registry = request.registry
-        if not IIllustration.providedBy(context):
-            context = Illustration()
-        terms = [SimpleTerm(name, title=translate(adapter.label))
-                 for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer),
-                                             key=lambda x: x[1].weight)]
-        super(IllustrationRendererVocabulary, self).__init__(terms)
+    content_interface = IIllustration