Added manager, folders and posts factory settings and attributes
authorThierry Florac <thierry.florac@onf.fr>
Tue, 28 Nov 2017 17:25:50 +0100
changeset 297 4f385d0a5ce7
parent 296 aaf2eac56470
child 298 42f146b4d946
Added manager, folders and posts factory settings and attributes
src/pyams_content/shared/blog/__init__.py
src/pyams_content/shared/blog/interfaces/__init__.py
src/pyams_content/shared/blog/manager.py
src/pyams_content/shared/blog/zmi/__init__.py
src/pyams_content/shared/blog/zmi/manager.py
--- a/src/pyams_content/shared/blog/__init__.py	Tue Nov 28 17:24:57 2017 +0100
+++ b/src/pyams_content/shared/blog/__init__.py	Tue Nov 28 17:25:50 2017 +0100
@@ -21,6 +21,7 @@
 from pyams_content.features.preview.interfaces import IPreviewTarget
 from pyams_content.features.review.interfaces import IReviewTarget
 from pyams_content.shared.blog.interfaces import IWfBlogPost, BLOG_CONTENT_TYPE, BLOG_CONTENT_NAME, IBlogPost
+from pyams_workflow.interfaces import IWorkflow, IWorkflowVersions, IWorkflowState
 
 # import packages
 from pyams_content.shared.common import WfSharedContent, register_content_type, SharedContent
@@ -43,3 +44,10 @@
     """Worfklow managed blog post class"""
 
     content_class = WfBlogPost
+
+    def is_deletable(self):
+        workflow = IWorkflow(self)
+        for version in IWorkflowVersions(self).get_versions():
+            if IWorkflowState(version).state != workflow.initial_state:
+                return False
+        return True
--- a/src/pyams_content/shared/blog/interfaces/__init__.py	Tue Nov 28 17:24:57 2017 +0100
+++ b/src/pyams_content/shared/blog/interfaces/__init__.py	Tue Nov 28 17:25:50 2017 +0100
@@ -16,13 +16,15 @@
 # import standard library
 
 # import interfaces
-from pyams_content.shared.common.interfaces import ISharedSite, ISharedTool, IWfSharedContent, ISharedContent
+from pyams_content.shared.common.interfaces import ISharedSite, ISharedTool, IWfSharedContent, ISharedContent, \
+    IDeletableElement
 from pyams_sequence.interfaces import ISequentialIdTarget
 from pyams_workflow.interfaces import IWorkflowPublicationSupport
 from zope.container.interfaces import IContainer
 
 # import packages
 from zope.container.constraints import containers, contains
+from zope.interface import Attribute
 
 from pyams_content import _
 
@@ -35,20 +37,22 @@
     """Blog topic interface"""
 
 
-class IBlogPost(ISharedContent):
+class IBlogPost(ISharedContent, IDeletableElement):
     """Workflow managed blog post interface"""
 
     containers('.IBlogFolder')
 
 
-class IBlogFolder(IContainer):
+class IBlogFolder(IContainer, IDeletableElement):
     """Blog folder interface"""
 
     containers('.IBlogManager', '.IBlogFolder')
     contains('.IBlogFolder', '.IBlogPost')
 
 
-class IBlogManager(ISharedSite, ISharedTool, IWorkflowPublicationSupport, ISequentialIdTarget):
+class IBlogManager(ISharedSite, ISharedTool, IWorkflowPublicationSupport, IDeletableElement, ISequentialIdTarget):
     """Blog manager interface"""
 
     contains(IBlogFolder)
+
+    folder_factory = Attribute("Blog folder factory")
--- a/src/pyams_content/shared/blog/manager.py	Tue Nov 28 17:24:57 2017 +0100
+++ b/src/pyams_content/shared/blog/manager.py	Tue Nov 28 17:25:50 2017 +0100
@@ -39,17 +39,31 @@
 class BlogFolder(Folder):
     """Blog folder class"""
 
+    def is_deletable(self):
+        for element in self.values():
+            if not element.is_deletable():
+                return False
+        return True
+
 
 @implementer(IBlogManager, IParagraphFactorySettings, IThemesManagerTarget, IAttributeAnnotatable, IPortalContext)
 class BlogManager(SharedTool, UserSkinnableContent):
     """Nlog manager class"""
 
+    folder_factory = BlogFolder
+
     shared_content_type = BLOG_CONTENT_TYPE
     shared_content_factory = BlogPost
 
     allowed_paragraphs = FieldProperty(IParagraphFactorySettings['allowed_paragraphs'])
     auto_created_paragraphs = FieldProperty(IParagraphFactorySettings['auto_created_paragraphs'])
 
+    def is_deletable(self):
+        for element in self.values():
+            if not element.is_deletable():
+                return False
+        return True
+
 
 @subscriber(IObjectAddedEvent, context_selector=IBlogManager)
 def handle_added_blog_manager(event):
--- a/src/pyams_content/shared/blog/zmi/__init__.py	Tue Nov 28 17:24:57 2017 +0100
+++ b/src/pyams_content/shared/blog/zmi/__init__.py	Tue Nov 28 17:25:50 2017 +0100
@@ -27,7 +27,6 @@
 from pyams_zmi.layer import IAdminLayer
 
 # import packages
-from pyams_content.shared.blog.manager import BlogFolder
 from pyams_content.shared.common.zmi import SharedContentAddForm, SharedContentAJAXAddForm
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.interfaces import IContentTitle
@@ -88,10 +87,10 @@
         year, month = now.strftime('%Y:%m').split(':')
         year_folder = self.context.get(year)
         if year_folder is None:
-            year_folder = self.context[year] = BlogFolder()
+            year_folder = self.context[year] = self.context.folder_factory()
         month_folder = year_folder.get(month)
         if month_folder is None:
-            month_folder = year_folder[month] = BlogFolder()
+            month_folder = year_folder[month] = self.context.folder_factory()
         # check title language
         added = False
         i18n_manager = II18nManager(self.context)
--- a/src/pyams_content/shared/blog/zmi/manager.py	Tue Nov 28 17:24:57 2017 +0100
+++ b/src/pyams_content/shared/blog/zmi/manager.py	Tue Nov 28 17:25:50 2017 +0100
@@ -30,7 +30,6 @@
 from z3c.form.interfaces import IDataExtractedEvent
 
 # import packages
-from pyams_content.shared.blog.manager import BlogManager
 from pyams_form.form import AJAXAddForm, AJAXEditForm
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.table import DefaultElementEditorAdapter
@@ -43,6 +42,7 @@
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm
 from pyramid.events import subscriber
+from pyramid.path import DottedNameResolver
 from pyramid.view import view_config
 from z3c.form import field
 from zope.interface import Invalid
@@ -90,7 +90,11 @@
     edit_permission = None
 
     def create(self, data):
-        return BlogManager()
+        factory = self.request.registry.settings.get('pyams_content.config.blog_factory')
+        if factory is None:
+            factory = 'pyams_content.shared.blog.manager.BlogManager'
+        factory = DottedNameResolver().resolve(factory)
+        return factory()
 
     def add(self, object):
         short_name = II18n(object).query_attribute('short_name', request=self.request)