Updated visible paragraphs iterator
authorThierry Florac <thierry.florac@onf.fr>
Mon, 03 Sep 2018 15:37:33 +0200
changeset 914 76f637363cfd
parent 913 5481b19fd47c
child 915 ad76d21ab2a4
Updated visible paragraphs iterator
src/pyams_content/component/paragraph/container.py
--- a/src/pyams_content/component/paragraph/container.py	Mon Sep 03 13:40:59 2018 +0200
+++ b/src/pyams_content/component/paragraph/container.py	Mon Sep 03 15:37:33 2018 +0200
@@ -16,8 +16,8 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.paragraph.interfaces import IParagraphContainer, IParagraphContainerTarget, \
-    PARAGRAPH_CONTAINER_KEY
+from pyams_content.component.paragraph.interfaces import IParagraphFactory, IParagraphContainer, \
+    IParagraphContainerTarget, PARAGRAPH_CONTAINER_KEY
 from pyams_content.features.checker.interfaces import IContentChecker
 from zope.location.interfaces import ISublocations
 from zope.traversing.interfaces import ITraversable
@@ -26,6 +26,7 @@
 from pyams_content.features.checker import BaseContentChecker
 from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
 from pyams_utils.container import BTreeOrderedContainer
+from pyams_utils.registry import get_global_registry
 from zope.interface import implementer
 
 from pyams_content import _
@@ -49,7 +50,11 @@
             if anchors_only and not paragraph.anchor:
                 continue
             if factories:
-                has_factory = tuple(filter(lambda x: x.content_type == paragraph.__class__))
+                registry = get_global_registry()
+                has_factory = False
+                for factory_name in factories:
+                    factory = registry.queryUtility(IParagraphFactory, name=factory_name)
+                    has_factory = (factory is not None) and (factory.content_type == paragraph.__class__)
                 if not has_factory:
                     continue
             yield paragraph