Updated header
authorThierry Florac <tflorac@ulthar.net>
Wed, 12 Dec 2018 16:02:53 +0100
changeset 1159 fc062f9e32c0
parent 1158 ae370f498f04
child 1160 33de88e935cf
Updated header
src/pyams_content/shared/site/zmi/container.py
src/pyams_content/shared/site/zmi/folder.py
src/pyams_content/shared/site/zmi/templates/container-header.pt
--- a/src/pyams_content/shared/site/zmi/container.py	Wed Dec 12 14:40:56 2018 +0100
+++ b/src/pyams_content/shared/site/zmi/container.py	Wed Dec 12 16:02:53 2018 +0100
@@ -21,12 +21,12 @@
 from z3c.form import field
 from z3c.table.column import GetAttrColumn
 from z3c.table.interfaces import IColumn, IValues
-from zope.interface import implementer
+from zope.interface import implementer, Interface
 from zope.intid.interfaces import IIntIds
 from zope.lifecycleevent import ObjectMovedEvent
 
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION, MANAGE_SITE_PERMISSION
-from pyams_content.shared.common.interfaces import ISharedContent
+from pyams_content.shared.common.interfaces import ISharedContent, ISharedSite
 from pyams_content.shared.common.interfaces.zmi import IDashboardTable
 from pyams_content.shared.common.zmi.dashboard import SharedToolDashboardOwnerColumn, SharedToolDashboardSequenceColumn, \
     SharedToolDashboardStatusColumn, SharedToolDashboardStatusDateColumn, SharedToolDashboardStatusPrincipalColumn, \
@@ -50,7 +50,9 @@
 from pyams_skin.viewlet.breadcrumb import BreadcrumbAdminLayerItem
 from pyams_skin.viewlet.menu import MenuItem
 from pyams_skin.viewlet.toolbar import ToolbarMenuItem
+from pyams_template.template import template_config
 from pyams_utils.adapter import ContextRequestAdapter, ContextRequestViewAdapter, adapter_config
+from pyams_utils.date import format_datetime
 from pyams_utils.fanstatic import get_resource_path
 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 from pyams_utils.interfaces.traversing import IPathElements
@@ -59,7 +61,7 @@
 from pyams_utils.traversing import get_parent
 from pyams_utils.url import absolute_url
 from pyams_viewlet.manager import viewletmanager_config
-from pyams_viewlet.viewlet import viewlet_config
+from pyams_viewlet.viewlet import viewlet_config, contentprovider_config
 from pyams_workflow.interfaces import IWorkflowPublicationInfo, IWorkflowVersions
 from pyams_zmi.form import AdminDialogEditForm
 from pyams_zmi.interfaces.menu import IPropertiesMenu, ISiteManagementMenu
@@ -69,6 +71,52 @@
 from pyams_content import _
 
 
+@contentprovider_config(name='content_header', context=ISharedSite, view=Interface, layer=IPyAMSLayer)
+@contentprovider_config(name='content_header', context=ISiteContainer, view=Interface, layer=IPyAMSLayer)
+@template_config(template='templates/container-header.pt', layer=IPyAMSLayer)
+class SiteContainerHeaderContentProvider(object):
+    """Site container header content provider"""
+
+    back_url = '#site-tree.html'
+    back_target = None
+
+    icon_class = ''
+
+    def __init__(self, context, request, view):
+        super(SiteContainerHeaderContentProvider, self).__init__(context, request, view)
+        # check publication state
+        translate = self.request.localizer.translate
+        now = tztime(datetime.utcnow())
+        pub_info = IWorkflowPublicationInfo(self.context)
+        if pub_info.publication_effective_date:
+            if pub_info.publication_effective_date <= now:
+                if pub_info.publication_expiration_date:
+                    if pub_info.publication_effective_date > now:
+                        self.state = '<span class="text-danger">{}</span>'.format(
+                            translate(_("Retired since {}")).format(
+                                format_datetime(pub_info.publication_expiration_date)))
+                    else:
+                        self.state = translate(_("Published since {} until {}")).format(
+                            format_datetime(pub_info.publication_effective_date),
+                            format_datetime(pub_info.publication_expiration_date))
+                else:
+                    self.state = translate(_("Published since {}")).format(
+                        format_datetime(pub_info.publication_effective_date))
+            else:
+                if pub_info.publication_expiration_date:
+                    self.state = '<span class="text-danger">{}</span>'.format(
+                        translate(_("To be published from {} to {}")).format(
+                            format_datetime(pub_info.publication_effective_date),
+                            format_datetime(pub_info.publication_expiration_date)))
+                else:
+                    self.state = '<span class="text-danger">{}</span>'.format(
+                        translate(_("Published after {}")).format(
+                            format_datetime(pub_info.publication_effective_date)))
+        else:
+            self.state = '<span class="text-danger">{}</span>'.format(
+                translate(_("Not published")))
+
+
 @adapter_config(context=(IBaseSiteItem, IAdminLayer), provides=IBreadcrumbItem)
 class SiteContainerBreadcrumbAdapter(BreadcrumbAdminLayerItem):
     """Site container breadcrumb adapter"""
@@ -84,9 +132,9 @@
 
     @property
     def label(self):
-        return '{content} ({blog})'.format(
+        return '{content} ({site})'.format(
             content=self.request.localizer.translate(WfSiteTopic.content_name),
-            blog=II18n(self.context).query_attribute('title', request=self.request))
+            site=II18n(self.context).query_attribute('title', request=self.request))
 
 
 #
--- a/src/pyams_content/shared/site/zmi/folder.py	Wed Dec 12 14:40:56 2018 +0100
+++ b/src/pyams_content/shared/site/zmi/folder.py	Wed Dec 12 16:02:53 2018 +0100
@@ -18,25 +18,25 @@
 from z3c.form.interfaces import IDataExtractedEvent
 from zope.interface import Interface, Invalid
 from zope.intid.interfaces import IIntIds
-from zope.schema import Text, Int
+from zope.schema import Int, Text
 
 from pyams_content.interfaces import MANAGE_SITE_PERMISSION, MANAGE_TOOL_PERMISSION
 from pyams_content.shared.common.interfaces import IBaseSharedTool
 from pyams_content.shared.common.zmi.manager import SharedToolPropertiesEditForm
-from pyams_content.shared.site.interfaces import ISiteContainer, ISiteManager, ISiteFolder
+from pyams_content.shared.site.interfaces import ISiteContainer, ISiteFolder, ISiteManager
 from pyams_content.shared.site.zmi.widget import SiteManagerFoldersSelectorFieldWidget
 from pyams_form.form import AJAXAddForm, ajax_config
 from pyams_form.group import NamedWidgetsGroup
 from pyams_form.interfaces.form import IInnerSubForm
-from pyams_i18n.interfaces import INegotiator, II18n
+from pyams_i18n.interfaces import II18n, INegotiator
 from pyams_i18n.schema import I18nTextLineField
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.interfaces.container import ITableElementName, ITableElementEditor
-from pyams_skin.interfaces.viewlet import IToolbarAddingMenu, IMenuHeader
+from pyams_skin.interfaces.container import ITableElementEditor, ITableElementName
+from pyams_skin.interfaces.viewlet import IMenuHeader, IToolbarAddingMenu
 from pyams_skin.layer import IPyAMSLayer
 from pyams_skin.table import DefaultElementEditorAdapter
 from pyams_skin.viewlet.toolbar import ToolbarMenuItem
-from pyams_utils.adapter import adapter_config, ContextRequestAdapter
+from pyams_utils.adapter import ContextRequestAdapter, adapter_config
 from pyams_utils.registry import get_utility
 from pyams_utils.traversing import get_parent
 from pyams_utils.unicode import translate_string
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/site/zmi/templates/container-header.pt	Wed Dec 12 16:02:53 2018 +0100
@@ -0,0 +1,23 @@
+<tal:block i18n:domain="pyams_content"
+		   define="config tales:back_configuration">
+	<tal:if condition="config.display_shared_tool_title">
+		<h1 class="page-title margin-bottom-5"
+			tal:define="back_url view.back_url">
+			<a class="font-xs hint" data-ams-target="#content"
+			   title="Back to previous page" i18n:attributes="title"
+			   tal:attributes="href back_url;
+							   data-ams-target view.back_target;">
+				<i class="fa fa-chevron-left padding-right-10"></i>
+			</a>
+			<tal:if condition="config.display_content_icon">
+				<i tal:attributes="class view.icon_class"></i>
+			</tal:if>
+			<tal:var content="view.title" />
+		</h1>
+	</tal:if>
+	<div tal:attributes="class 'margin-left-10 margin-bottom-5 padding-left-20' if config.display_shared_tool_title else 'margin-bottom-5 padding-left-10'">
+		<span class="bold content-oid">${tales:oid(context)}</span> :
+		<span class="bold content-title">${i18n:context.title}</span><br />
+		<span class="content-state">${structure:view.state}</span>
+	</div>
+</tal:block>
\ No newline at end of file