Added allowed paragraphs types to shared tools
authorThierry Florac <thierry.florac@onf.fr>
Mon, 02 Oct 2017 17:03:26 +0200
changeset 192 8a16d2f507d7
parent 191 6d0f21087473
child 193 595d2965fc4d
Added allowed paragraphs types to shared tools
src/pyams_content/component/association/paragraph.py
src/pyams_content/component/association/zmi/paragraph.py
src/pyams_content/component/gallery/paragraph.py
src/pyams_content/component/gallery/zmi/paragraph.py
src/pyams_content/component/illustration/zmi/paragraph.py
src/pyams_content/component/paragraph/header.py
src/pyams_content/component/paragraph/html.py
src/pyams_content/component/paragraph/interfaces/__init__.py
src/pyams_content/component/paragraph/video.py
src/pyams_content/component/paragraph/zmi/__init__.py
src/pyams_content/component/paragraph/zmi/header.py
src/pyams_content/component/paragraph/zmi/html.py
src/pyams_content/component/paragraph/zmi/video.py
src/pyams_content/shared/blog/manager.py
src/pyams_content/shared/imagemap/zmi/paragraph.py
src/pyams_content/shared/news/manager.py
--- a/src/pyams_content/component/association/paragraph.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/association/paragraph.py	Mon Oct 02 17:03:26 2017 +0200
@@ -37,7 +37,7 @@
     icon_hint = _("Associations paragraph")
 
 
-@utility_config(name='Associations paragraph', provides=IParagraphFactory)
+@utility_config(name='Associations', provides=IParagraphFactory)
 class AssociationParagraphFactory(object):
     """Associations paragraph factory"""
 
--- a/src/pyams_content/component/association/zmi/paragraph.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/association/zmi/paragraph.py	Mon Oct 02 17:03:26 2017 +0200
@@ -32,11 +32,10 @@
 
 # import packages
 from pyams_content.component.association.paragraph import AssociationParagraph
-from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
+    BaseParagraphAddMenu
 from pyams_content.component.paragraph.zmi.container import ParagraphContainerView
-from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.viewlet.toolbar import ToolbarMenuItem
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.traversing import get_parent
@@ -51,13 +50,13 @@
 
 @viewlet_config(name='add-association-paragraph.menu', context=IParagraphContainerTarget, view=ParagraphContainerView,
                 layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=95)
-class AssociationParagraphAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
+class AssociationParagraphAddMenu(BaseParagraphAddMenu):
     """Associations paragraph add menu"""
 
     label = _("Add associations paragraph...")
     label_css_class = 'fa fa-fw fa-link'
     url = 'add-association-paragraph.html'
-    modal_target = True
+    paragraph_type = 'Associations'
 
 
 @pagelet_config(name='add-association-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
--- a/src/pyams_content/component/gallery/paragraph.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/gallery/paragraph.py	Mon Oct 02 17:03:26 2017 +0200
@@ -36,7 +36,7 @@
     icon_hint = _("Images gallery")
 
 
-@utility_config(name='gallery', provides=IParagraphFactory)
+@utility_config(name='Gallery', provides=IParagraphFactory)
 class GalleryFactory(object):
     """Gallery paragraph factory"""
 
--- a/src/pyams_content/component/gallery/zmi/paragraph.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/gallery/zmi/paragraph.py	Mon Oct 02 17:03:26 2017 +0200
@@ -31,12 +31,12 @@
 
 # import packages
 from pyams_content.component.gallery.paragraph import Gallery
-from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
+    BaseParagraphAddMenu
 from pyams_content.component.paragraph.zmi.container import ParagraphContainerView
 from pyams_content.shared.common.zmi import WfSharedContentPermissionMixin
-from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.viewlet.toolbar import ToolbarMenuItem, ToolbarAction
+from pyams_skin.viewlet.toolbar import ToolbarAction
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.traversing import get_parent
@@ -51,13 +51,13 @@
 
 @viewlet_config(name='add-gallery.menu', context=IParagraphContainerTarget, view=ParagraphContainerView,
                 layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=65)
-class GalleryAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
+class GalleryAddMenu(BaseParagraphAddMenu):
     """Gallery add menu"""
 
     label = _("Add images gallery...")
     label_css_class = 'fa fa-fw fa-picture-o'
     url = 'add-gallery.html'
-    modal_target = True
+    paragraph_type = 'Gallery'
 
 
 @pagelet_config(name='add-gallery.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
--- a/src/pyams_content/component/illustration/zmi/paragraph.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/illustration/zmi/paragraph.py	Mon Oct 02 17:03:26 2017 +0200
@@ -31,11 +31,10 @@
 
 # import packages
 from pyams_content.component.illustration.paragraph import Illustration
-from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
+    BaseParagraphAddMenu
 from pyams_content.component.paragraph.zmi.container import ParagraphContainerView
-from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.viewlet.toolbar import ToolbarMenuItem
 from pyams_utils.adapter import adapter_config
 from pyams_utils.traversing import get_parent
 from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider
@@ -53,13 +52,13 @@
 
 @viewlet_config(name='add-illustration.menu', context=IParagraphContainerTarget, view=ParagraphContainerView,
                 layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=60)
-class IllustrationAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
+class IllustrationAddMenu(BaseParagraphAddMenu):
     """Illustration add menu"""
 
     label = _("Add illustration...")
     label_css_class = 'fa fa-fw fa-file-image-o'
     url = 'add-illustration.html'
-    modal_target = True
+    paragraph_type = 'Illustration'
 
 
 @pagelet_config(name='add-illustration.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
--- a/src/pyams_content/component/paragraph/header.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/paragraph/header.py	Mon Oct 02 17:03:26 2017 +0200
@@ -45,7 +45,7 @@
     header = FieldProperty(IHeaderParagraph['header'])
 
 
-@utility_config(name='Header paragraph', provides=IParagraphFactory)
+@utility_config(name='Header', provides=IParagraphFactory)
 class HTMLParagraphFactory(object):
     """HTML paragraph factory"""
 
--- a/src/pyams_content/component/paragraph/html.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/paragraph/html.py	Mon Oct 02 17:03:26 2017 +0200
@@ -56,7 +56,7 @@
     body = FieldProperty(IHTMLParagraph['body'])
 
 
-@utility_config(name='HTML paragraph', provides=IParagraphFactory)
+@utility_config(name='HTML', provides=IParagraphFactory)
 class HTMLParagraphFactory(object):
     """HTML paragraph factory"""
 
--- a/src/pyams_content/component/paragraph/interfaces/__init__.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/paragraph/interfaces/__init__.py	Mon Oct 02 17:03:26 2017 +0200
@@ -24,7 +24,7 @@
 from pyams_i18n.schema import I18nTextLineField
 from zope.container.constraints import containers, contains
 from zope.interface import Interface, Attribute
-from zope.schema import Bool, List, Choice
+from zope.schema import Bool, List, Choice, Set
 
 from pyams_content import _
 
@@ -76,6 +76,11 @@
     This interface is used to defined default auto-created paragraphs
     for a given shared tool."""
 
+    allowed_paragraphs = Set(title=_("Allowed paragraphs"),
+                             description=_("List of paragraphs allowed for this content type"),
+                             required=False,
+                             value_type=Choice(vocabulary='PyAMS paragraph factories'))
+
     auto_created_paragraphs = List(title=_("Default paragraphs"),
                                    description=_("List of paragraphs automatically added to a new content"),
                                    required=False,
--- a/src/pyams_content/component/paragraph/video.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/paragraph/video.py	Mon Oct 02 17:03:26 2017 +0200
@@ -48,7 +48,7 @@
     data = FileProperty(IVideoParagraph['data'])
 
 
-@utility_config(name='video', provides=IParagraphFactory)
+@utility_config(name='Video', provides=IParagraphFactory)
 class VideoParagraphFactory(object):
     """Video paragraph factory"""
 
--- a/src/pyams_content/component/paragraph/zmi/__init__.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/paragraph/zmi/__init__.py	Mon Oct 02 17:03:26 2017 +0200
@@ -27,9 +27,12 @@
 # import packages
 from pyams_form.form import AJAXEditForm, AJAXAddForm
 from pyams_form.help import FormHelp
+from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.viewlet.menu import MenuItem
+from pyams_skin.viewlet.toolbar import ToolbarMenuItem
 from pyams_utils.adapter import adapter_config
+from pyams_utils.traversing import get_parent
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogEditForm
 from pyramid.view import view_config
@@ -47,7 +50,7 @@
 class DefaultParagraphsSettingsMenu(MenuItem):
     """Default paragraphs settings menu"""
 
-    label = _("Default paragraphs...")
+    label = _("Paragraphs types...")
     icon_class = 'fa-paragraph'
     url = 'default-paragraphs.html'
     modal_target = True
@@ -58,7 +61,7 @@
 class DefaultParagraphsEditForm(AdminDialogEditForm):
     """Default paragraphs edit form"""
 
-    legend = _("Default paragraphs")
+    legend = _("Paragraphs types")
 
     fields = field.Fields(IParagraphFactorySettings)
     ajax_handler = 'default-paragraphs.json'
@@ -75,7 +78,9 @@
 class DefaultParagraphsEditFormHelp(FormHelp):
     """Default paragraphs edit form help"""
 
-    message = _("These paragraphs will be added automatically to any new created content.")
+    message = _("You can define which types of paragraphs are allowed in this container.\n\n"
+                "Default paragraphs will be added automatically (in selected order) to any new created content.\n\n"
+                "NOTICE: removing types from allowed types list will have no effect on already created contents!")
     message_format = 'rest'
 
 
@@ -83,6 +88,19 @@
 # Base paragraph forms
 #
 
+class BaseParagraphAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
+    """Base paragraph add menu"""
+
+    paragraph_type = None
+    modal_target = True
+
+    def __new__(cls, context, request, view, manager):
+        settings = get_parent(context, IParagraphFactorySettings)
+        if (settings is not None) and (cls.paragraph_type not in settings.allowed_paragraphs):
+            return None
+        return ToolbarMenuItem.__new__(cls)
+
+
 class BaseParagraphAJAXAddForm(AJAXAddForm):
     """Base paragraph AJAX add form"""
 
--- a/src/pyams_content/component/paragraph/zmi/header.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/paragraph/zmi/header.py	Mon Oct 02 17:03:26 2017 +0200
@@ -30,11 +30,10 @@
 
 # import packages
 from pyams_content.component.paragraph.header import HeaderParagraph
-from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
+    BaseParagraphAddMenu
 from pyams_content.component.paragraph.zmi.container import ParagraphContainerView
-from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.viewlet.toolbar import ToolbarMenuItem
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.traversing import get_parent
@@ -49,13 +48,13 @@
 
 @viewlet_config(name='add-header-paragraph.menu', context=IParagraphContainerTarget, view=ParagraphContainerView,
                 layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=40)
-class HeaderParagraphAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
+class HeaderParagraphAddMenu(BaseParagraphAddMenu):
     """Header paragraph add menu"""
 
     label = _("Add header paragraph...")
     label_css_class = 'fa fa-fw fa-header'
     url = 'add-header-paragraph.html'
-    modal_target = True
+    paragraph_type = 'Header'
 
 
 @pagelet_config(name='add-header-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
--- a/src/pyams_content/component/paragraph/zmi/html.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/paragraph/zmi/html.py	Mon Oct 02 17:03:26 2017 +0200
@@ -34,11 +34,10 @@
 # import packages
 from pyams_content.component.association.zmi import AssociationsTable
 from pyams_content.component.paragraph.html import HTMLParagraph
-from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
+    BaseParagraphAddMenu
 from pyams_content.component.paragraph.zmi.container import ParagraphContainerView
-from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.viewlet.toolbar import ToolbarMenuItem
 from pyams_template.template import template_config
 
 from pyams_utils.adapter import adapter_config
@@ -59,13 +58,13 @@
 
 @viewlet_config(name='add-html-paragraph.menu', context=IParagraphContainerTarget, view=ParagraphContainerView,
                 layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=50)
-class HTMLParagraphAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
+class HTMLParagraphAddMenu(BaseParagraphAddMenu):
     """HTML paragraph add menu"""
 
     label = _("Add HTML paragraph...")
     label_css_class = 'fa fa-fw fa-html5'
     url = 'add-html-paragraph.html'
-    modal_target = True
+    paragraph_type = 'HTML'
 
 
 @pagelet_config(name='add-html-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
--- a/src/pyams_content/component/paragraph/zmi/video.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/component/paragraph/zmi/video.py	Mon Oct 02 17:03:26 2017 +0200
@@ -18,7 +18,8 @@
     IParagraphSummary
 from pyams_content.component.paragraph.interfaces.video import IVideoParagraph
 from pyams_content.component.paragraph.video import VideoParagraph
-from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
+    BaseParagraphAddMenu
 from pyams_content.component.paragraph.zmi.container import ParagraphContainerView
 from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
@@ -55,13 +56,13 @@
 
 @viewlet_config(name='add-video-paragraph.menu', context=IParagraphContainerTarget, view=ParagraphContainerView,
                 layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=70)
-class VideoParagraphAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
+class VideoParagraphAddMenu(BaseParagraphAddMenu):
     """Video paragraph add menu"""
 
     label = _("Add video paragraph...")
     label_css_class = 'fa fa-fw fa-film'
     url = 'add-video-paragraph.html'
-    modal_target = True
+    paragraph_type = 'Video'
 
 
 @pagelet_config(name='add-video-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
--- a/src/pyams_content/shared/blog/manager.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/shared/blog/manager.py	Mon Oct 02 17:03:26 2017 +0200
@@ -47,6 +47,7 @@
     shared_content_type = BLOG_CONTENT_TYPE
     shared_content_factory = BlogPost
 
+    allowed_paragraphs = FieldProperty(IParagraphFactorySettings['allowed_paragraphs'])
     auto_created_paragraphs = FieldProperty(IParagraphFactorySettings['auto_created_paragraphs'])
 
 
--- a/src/pyams_content/shared/imagemap/zmi/paragraph.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/shared/imagemap/zmi/paragraph.py	Mon Oct 02 17:03:26 2017 +0200
@@ -16,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.association.interfaces import IAssociationContainer, IAssociationInfo
+from pyams_content.component.association.interfaces import IAssociationInfo
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \
     IParagraphSummary
 from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor
@@ -30,13 +30,12 @@
 from z3c.form.interfaces import INPUT_MODE
 
 # import packages
-from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
+    BaseParagraphAddMenu
 from pyams_content.component.paragraph.zmi.container import ParagraphContainerView
 from pyams_content.shared.imagemap.paragraph import ImageMapParagraph
-from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.viewlet.toolbar import ToolbarMenuItem
-from pyams_template.template import template_config, get_view_template
+from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.traversing import get_parent
 from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider
@@ -50,13 +49,13 @@
 
 @viewlet_config(name='add-imagemap-paragraph.menu', context=IParagraphContainerTarget, view=ParagraphContainerView,
                 layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=80)
-class ImagemapParagraphAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
+class ImagemapParagraphAddMenu(BaseParagraphAddMenu):
     """Image map paragraph add menu"""
 
     label = _("Add image map...")
     label_css_class = 'fa fa-fw fa-location-arrow'
     url = 'add-imagemap-paragraph.html'
-    modal_target = True
+    paragraph_type = 'ImageMap'
 
 
 @pagelet_config(name='add-imagemap-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
--- a/src/pyams_content/shared/news/manager.py	Mon Oct 02 15:24:08 2017 +0200
+++ b/src/pyams_content/shared/news/manager.py	Mon Oct 02 17:03:26 2017 +0200
@@ -39,6 +39,7 @@
     shared_content_type = NEWS_CONTENT_TYPE
     shared_content_factory = NewsEvent
 
+    allowed_paragraphs = FieldProperty(IParagraphFactorySettings['allowed_paragraphs'])
     auto_created_paragraphs = FieldProperty(IParagraphFactorySettings['auto_created_paragraphs'])