src/pyams_content/component/illustration/__init__.py
changeset 682 d093aba47072
parent 591 b694d5667d17
child 686 43ebbd99dd62
--- a/src/pyams_content/component/illustration/__init__.py	Thu Jun 14 10:40:46 2018 +0200
+++ b/src/pyams_content/component/illustration/__init__.py	Thu Jun 14 14:03:31 2018 +0200
@@ -17,7 +17,7 @@
 
 # import interfaces
 from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationTarget, \
-    ILLUSTRATION_KEY, ILLUSTRATION_RENDERERS
+    ILLUSTRATION_KEY, ILLUSTRATION_RENDERERS, IBasicIllustration, IBasicIllustrationTarget, BASIC_ILLUSTRATION_KEY
 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
 from pyams_file.interfaces import IFileInfo, IImage, IResponsiveImage
 from pyams_i18n.interfaces import INegotiator, II18n, II18nManager
@@ -46,17 +46,14 @@
 from pyams_content import _
 
 
-@implementer(IIllustration)
-@factory_config(provided=IIllustration)
-class Illustration(RenderedContentMixin, Persistent, Contained):
+@implementer(IBasicIllustration)
+@factory_config(provided=IBasicIllustration)
+class BasicIllustration(Persistent, Contained):
     """Illustration persistent class"""
 
     _data = I18nFileProperty(IIllustration['data'])
     title = FieldProperty(IIllustration['title'])
     alt_title = FieldProperty(IIllustration['alt_title'])
-    description = FieldProperty(IIllustration['description'])
-    author = FieldProperty(IIllustration['author'])
-    renderer = FieldProperty(IIllustration['renderer'])
 
     @property
     def data(self):
@@ -70,6 +67,28 @@
                 alsoProvides(data, IResponsiveImage)
 
 
+@adapter_config(context=IBasicIllustrationTarget, provides=IIllustration)
+def basic_illustration_factory(context):
+    """Basic illustration factory"""
+
+    def illustration_callback(illustration):
+        get_current_registry().notify(ObjectAddedEvent(illustration, context, illustration.__name__))
+
+    return get_annotation_adapter(context, BASIC_ILLUSTRATION_KEY, BasicIllustration,
+                                  name='++illustration++',
+                                  callback=illustration_callback)
+
+
+@implementer(IIllustration)
+@factory_config(provided=IIllustration)
+class Illustration(RenderedContentMixin, BasicIllustration):
+    """Illustration persistent class"""
+
+    description = FieldProperty(IIllustration['description'])
+    author = FieldProperty(IIllustration['author'])
+    renderer = FieldProperty(IIllustration['renderer'])
+
+
 @adapter_config(context=IIllustrationTarget, provides=IIllustration)
 def illustration_factory(context):
     """Illustration factory"""
@@ -95,21 +114,21 @@
             info.description = II18n(illustration).get_attribute('alt_title', lang, request)
 
 
-@subscriber(IObjectAddedEvent, context_selector=IIllustration)
+@subscriber(IObjectAddedEvent, context_selector=IBasicIllustration)
 def handle_added_illustration(event):
     """Handle added illustration"""
     illustration = event.object
     update_illustration_properties(illustration)
 
 
-@subscriber(IObjectModifiedEvent, context_selector=IIllustration)
+@subscriber(IObjectModifiedEvent, context_selector=IBasicIllustration)
 def handle_modified_illustration(event):
     """Handle modified illustration"""
     illustration = event.object
     update_illustration_properties(illustration)
 
 
-@adapter_config(name='illustration', context=IIllustrationTarget, provides=ITraversable)
+@adapter_config(name='illustration', context=IBasicIllustrationTarget, provides=ITraversable)
 class IllustrationNamespace(ContextAdapter):
     """++illustration++ namespace adapter"""
 
@@ -118,12 +137,14 @@
         return registry.queryAdapter(self.context, IIllustration, name=name)
 
 
-@adapter_config(name='illustration', context=IIllustrationTarget, provides=ISublocations)
+@adapter_config(name='illustration', context=IBasicIllustrationTarget, provides=ISublocations)
 class IllustrationSublocations(ContextAdapter):
     """Illustration sub-locations adapter"""
 
     def sublocations(self):
-        return IIllustration(self.context),
+        registry = get_global_registry()
+        for name, adapter in registry.getAdapters((self, ), IBasicIllustration):
+            yield adapter
 
 
 @adapter_config(context=IIllustration, provides=IContentChecker)