--- a/src/pyams_content/shared/common/zmi/properties.py Wed Jul 12 11:49:11 2017 +0200
+++ b/src/pyams_content/shared/common/zmi/properties.py Wed Jul 12 11:50:34 2017 +0200
@@ -9,6 +9,7 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
+from pyramid.events import subscriber
__docformat__ = 'restructuredtext'
@@ -18,11 +19,13 @@
# import interfaces
from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
from pyams_content.shared.common.interfaces import IWfSharedContent
-from pyams_form.interfaces.form import IWidgetForm
+from pyams_form.interfaces.form import IWidgetForm, IInnerSubForm
from pyams_skin.interfaces import IInnerPage, IPageHeader
from pyams_skin.layer import IPyAMSLayer
+from pyams_workflow.interfaces import IWorkflowPublicationInfo, IWorkflowState, IWorkflow
from pyams_zmi.interfaces.menu import IContentManagementMenu, IPropertiesMenu
from pyams_zmi.layer import IAdminLayer
+from z3c.form.interfaces import DISPLAY_MODE, IDataExtractedEvent
# import packages
from pyams_content.shared.common.zmi import WfSharedContentHeaderAdapter
@@ -32,7 +35,7 @@
from pyams_utils.adapter import adapter_config
from pyams_viewlet.manager import viewletmanager_config
from pyams_viewlet.viewlet import viewlet_config
-from pyams_zmi.form import AdminEditForm
+from pyams_zmi.form import AdminEditForm, InnerAdminEditForm
from pyramid.view import view_config
from z3c.form import field
from zope.interface import implementer
@@ -96,3 +99,32 @@
"""Shared content properties header adapter"""
icon_class = 'fa fa-fw fa-edit'
+
+
+@adapter_config(name='publication',
+ context=(IWfSharedContent, IPyAMSLayer, SharedContentPropertiesEditForm),
+ provides=IInnerSubForm)
+class SharedContentPublicationPropertiesEditForm(InnerAdminEditForm):
+ """Shared content properties edit form extension"""
+
+ legend = _("Publication settings")
+ fieldset_class = 'bordered no-x-margin margin-y-10'
+
+ fields = field.Fields(IWorkflowPublicationInfo).select('publication_effective_date', 'push_end_date',
+ 'publication_expiration_date', 'displayed_publication_date')
+
+ def check_mode(self):
+ workflow = IWorkflow(self.context)
+ status = IWorkflowState(self.context)
+ if status.state not in workflow.update_states:
+ self.mode = DISPLAY_MODE
+ else:
+ super(SharedContentPublicationPropertiesEditForm, self).check_mode()
+
+
+@subscriber(IDataExtractedEvent, form_selector=SharedContentPublicationPropertiesEditForm)
+def handle_publication_properties_extraction(event):
+ """Handle publication form data extraction"""
+ data = event.data
+ if data.get('publication_expiration_date') and not data.get('push_end_date'):
+ data['push_end_date'] = data['publication_expiration_date']