Check for broken objects while iterating over paragraphs
authorThierry Florac <tflorac@ulthar.net>
Wed, 19 Sep 2018 11:15:53 +0200
changeset 959 0d42d6bc3fb9
parent 958 471b10c170eb
child 960 a9bcf47e9754
Check for broken objects while iterating over paragraphs
src/pyams_content/component/paragraph/container.py
--- a/src/pyams_content/component/paragraph/container.py	Wed Sep 19 10:57:47 2018 +0200
+++ b/src/pyams_content/component/paragraph/container.py	Wed Sep 19 11:15:53 2018 +0200
@@ -12,24 +12,21 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
+from ZODB.interfaces import IBroken
 from zope.interface import implementer
 from zope.location.interfaces import ISublocations
 from zope.traversing.interfaces import ITraversable
 
-from pyams_content import _
-# import interfaces
 from pyams_content.component.paragraph.interfaces import IParagraphFactory, IParagraphContainer, \
     IParagraphContainerTarget, PARAGRAPH_CONTAINER_KEY
-# import packages
 from pyams_content.features.checker import BaseContentChecker
 from pyams_content.features.checker.interfaces import IContentChecker
 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 pyams_content import _
+
 
 @implementer(IParagraphContainer)
 class ParagraphContainer(BTreeOrderedContainer):
@@ -46,11 +43,11 @@
         if names:
             for name in names:
                 paragraph = self.get(name)
-                if (paragraph is not None) and paragraph.visible:
+                if (paragraph is not None) and (not IBroken.providedBy(paragraph)) and paragraph.visible:
                     yield paragraph
         else:
             for paragraph in self.values():
-                if not paragraph.visible:
+                if IBroken.providedBy(paragraph) or not not paragraph.visible:
                     continue
                 if anchors_only and not paragraph.anchor:
                     continue
@@ -107,7 +104,7 @@
             if not paragraph.visible:
                 continue
             visible = True
-            for name, checker in sorted(registry.getAdapters((paragraph, ), IContentChecker),
+            for name, checker in sorted(registry.getAdapters((paragraph,), IContentChecker),
                                         key=lambda x: x[1].weight):
                 if name:
                     output.append('<div class="padding-left-20">')