# HG changeset patch # User Thierry Florac # Date 1535974859 -7200 # Node ID 5481b19fd47ce6c83efecc4621dd51280f8df847 # Parent f0716419669fda605583100a2fad3c9ca6a29ba8 Added method on paragraphs container to select paragraphs diff -r f0716419669f -r 5481b19fd47c src/pyams_content/component/paragraph/container.py --- a/src/pyams_content/component/paragraph/container.py Mon Sep 03 12:21:04 2018 +0200 +++ b/src/pyams_content/component/paragraph/container.py Mon Sep 03 13:40:59 2018 +0200 @@ -42,6 +42,18 @@ self[key] = value self.last_id += 1 + def get_visible_paragraphs(self, anchors_only=False, factories=None): + for paragraph in self.values(): + if not paragraph.visible: + continue + if anchors_only and not paragraph.anchor: + continue + if factories: + has_factory = tuple(filter(lambda x: x.content_type == paragraph.__class__)) + if not has_factory: + continue + yield paragraph + @adapter_config(context=IParagraphContainerTarget, provides=IParagraphContainer) def paragraph_container_factory(target): diff -r f0716419669f -r 5481b19fd47c src/pyams_content/component/paragraph/interfaces/__init__.py --- a/src/pyams_content/component/paragraph/interfaces/__init__.py Mon Sep 03 12:21:04 2018 +0200 +++ b/src/pyams_content/component/paragraph/interfaces/__init__.py Mon Sep 03 13:40:59 2018 +0200 @@ -66,11 +66,17 @@ def append(self, value): """Add given value to container""" + def get_visible_paragraphs(self, anchors_only=False, factories=None): + """Get visible paragraphs matching given arguments""" + class IParagraphContainerTarget(IAttributeAnnotatable): """Paragraphs container marker interface""" +PARAGRAPH_FACTORIES_VOCABULARY = 'PyAMS paragraph factories' + + class IParagraphFactory(Interface): """Paragraph factory utility interface""" @@ -93,7 +99,7 @@ auto_created_paragraphs = List(title=_("Default paragraphs"), description=_("List of paragraphs automatically added to a new content"), required=False, - value_type=Choice(vocabulary='PyAMS paragraph factories')) + value_type=Choice(vocabulary=PARAGRAPH_FACTORIES_VOCABULARY)) class IParagraphRenderer(IContentProvider):