src/pyams_content/component/paragraph/frame.py
changeset 1398 fc32ec8a8f53
parent 1157 ffb751b038cc
--- a/src/pyams_content/component/paragraph/frame.py	Fri Jul 03 14:42:15 2020 +0200
+++ b/src/pyams_content/component/paragraph/frame.py	Fri Jul 03 18:43:46 2020 +0200
@@ -12,17 +12,22 @@
 
 __docformat__ = 'restructuredtext'
 
+from pyramid.events import subscriber
 from zope.interface import implementer
+from zope.lifecycleevent import IObjectAddedEvent, IObjectModifiedEvent
 from zope.schema.fieldproperty import FieldProperty
 
 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
 from pyams_content.component.illustration.interfaces import IIllustrationTarget
 from pyams_content.component.links.interfaces import ILinkContainerTarget
-from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory
+from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, \
+    BaseParagraphFactory
+from pyams_content.component.paragraph.association import check_associations
 from pyams_content.component.paragraph.interfaces import IParagraphFactory
-from pyams_content.component.paragraph.interfaces.frame import FRAME_PARAGRAPH_NAME, FRAME_PARAGRAPH_RENDERERS, \
-    FRAME_PARAGRAPH_TYPE, IFrameParagraph
-from pyams_content.features.checker.interfaces import IContentChecker, MISSING_LANG_VALUE, MISSING_VALUE
+from pyams_content.component.paragraph.interfaces.frame import FRAME_PARAGRAPH_NAME, \
+    FRAME_PARAGRAPH_RENDERERS, FRAME_PARAGRAPH_TYPE, IFrameParagraph
+from pyams_content.features.checker.interfaces import IContentChecker, MISSING_LANG_VALUE, \
+    MISSING_VALUE
 from pyams_content.features.renderer import RenderersVocabulary
 from pyams_i18n.interfaces import II18n, II18nManager, INegotiator
 from pyams_utils.adapter import adapter_config
@@ -88,3 +93,20 @@
     """Framed text paragraph renderers vocabulary"""
 
     content_interface = IFrameParagraph
+
+
+@subscriber(IObjectAddedEvent, context_selector=IFrameParagraph)
+def handle_added_frame_paragraph(event):
+    """Check for new associations from added paragraph"""
+    paragraph = event.object
+    for lang, body in (paragraph.body or {}).items():
+        check_associations(paragraph, body, lang, notify=False)
+
+
+@subscriber(IObjectModifiedEvent, context_selector=IFrameParagraph)
+def handle_modified_frame_paragraph(event):
+    """Check for new associations from modified paragraph"""
+    paragraph = event.object
+    for lang, body in (paragraph.body or {}).items():
+        check_associations(paragraph, body, lang, notify=False)
+