Added vocabulary of current content paragraphs
authorThierry Florac <thierry.florac@onf.fr>
Fri, 09 Mar 2018 15:34:15 +0100
changeset 455 95582493a5ac
parent 454 1bd9d3cc2a7b
child 456 07646760c1b5
Added vocabulary of current content paragraphs
src/pyams_content/component/paragraph/__init__.py
--- a/src/pyams_content/component/paragraph/__init__.py	Fri Mar 09 12:35:35 2018 +0100
+++ b/src/pyams_content/component/paragraph/__init__.py	Fri Mar 09 15:34:15 2018 +0100
@@ -117,6 +117,25 @@
         super(ParagraphFactoriesVocabulary, self).__init__(terms)
 
 
+@vocabulary_config(name='PyAMS content paragraphs')
+class ContentParagraphsVocabulary(SimpleVocabulary):
+    """Content paragraphs vocabulary"""
+
+    def __init__(self, context):
+        request = check_request()
+        if not IParagraphContainerTarget.providedBy(context):
+            context = get_parent(context, IParagraphContainerTarget)
+        if context is not None:
+            terms = [SimpleTerm(para.__name__,
+                                title='ยง{0}: {1}'.format(index+1,
+                                                         II18n(para).query_attribute('title', request=request) or
+                                                         '----'))
+                     for index, para in enumerate(IParagraphContainer(context).values())]
+        else:
+            terms = []
+        super(ContentParagraphsVocabulary, self).__init__(terms)
+
+
 @adapter_config(context=IBaseParagraph, provides=IFormContextPermissionChecker)
 class BaseParagraphPermissionChecker(ContextAdapter):
     """Paragraph permission checker"""