Updated Header and Title portlets
authorThierry Florac <tflorac@ulthar.net>
Mon, 22 Jun 2020 18:31:49 +0200
changeset 506 0417bf1a6fa4
parent 505 f3f3e9792c10
child 507 01a4fac43422
Updated Header and Title portlets
src/pyams_default_theme/shared/common/__init__.py
src/pyams_default_theme/shared/common/portlet/specificities.py
src/pyams_default_theme/shared/common/portlet/templates/head.pt
src/pyams_default_theme/shared/common/portlet/templates/publication-date.pt
src/pyams_default_theme/shared/common/portlet/templates/title-portlet.pt
src/pyams_default_theme/shared/common/portlet/title.py
src/pyams_default_theme/shared/common/portlet/workflow.py
src/pyams_default_theme/shared/common/specificities.py
--- a/src/pyams_default_theme/shared/common/__init__.py	Mon Jun 22 18:30:36 2020 +0200
+++ b/src/pyams_default_theme/shared/common/__init__.py	Mon Jun 22 18:31:49 2020 +0200
@@ -118,7 +118,7 @@
     publication_info = IWorkflowPublicationInfo(context, None)
     if publication_info is not None:
         return format_date(publication_info.visible_publication_date,
-                           format=SH_DATE_FORMAT, request=request)
+                           format_string=SH_DATE_FORMAT, request=request)
 
 
 @adapter_config(name='pyams_date',
--- a/src/pyams_default_theme/shared/common/portlet/specificities.py	Mon Jun 22 18:30:36 2020 +0200
+++ b/src/pyams_default_theme/shared/common/portlet/specificities.py	Mon Jun 22 18:31:49 2020 +0200
@@ -14,7 +14,8 @@
 
 from zope.interface import Interface
 
-from pyams_content.shared.common.portlet.interfaces import ISharedContentSpecificitiesPortletSettings
+from pyams_content.shared.common.portlet.interfaces import \
+    ISharedContentSpecificitiesPortletSettings
 from pyams_default_theme import _
 from pyams_default_theme.shared.common.interfaces import ICustomContentSpecificitiesRenderer
 from pyams_portal.interfaces import IPortalContext, IPortletRenderer
@@ -27,7 +28,8 @@
 # Shared content specificities portlet renderer
 #
 
-@adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, ISharedContentSpecificitiesPortletSettings),
+@adapter_config(context=(IPortalContext, IPyAMSLayer, Interface,
+                         ISharedContentSpecificitiesPortletSettings),
                 provides=IPortletRenderer)
 class SharedContentSpecificitiesPortletRenderer(PortletRenderer):
     """Shared content specificities portlet default renderer"""
@@ -39,8 +41,8 @@
     def update(self):
         super(SharedContentSpecificitiesPortletRenderer, self).update()
         registry = self.request.registry
-        self.renderer = renderer = registry.queryMultiAdapter((self.context, self.request, self.view),
-                                                              ICustomContentSpecificitiesRenderer)
+        self.renderer = renderer = registry.queryMultiAdapter(
+            (self.context, self.request, self.view), ICustomContentSpecificitiesRenderer)
         if renderer is not None:
             renderer.update()
 
--- a/src/pyams_default_theme/shared/common/portlet/templates/head.pt	Mon Jun 22 18:30:36 2020 +0200
+++ b/src/pyams_default_theme/shared/common/portlet/templates/head.pt	Mon Jun 22 18:31:49 2020 +0200
@@ -7,6 +7,11 @@
 		<h1 tal:condition="settings.display_title">
 			${structure:provider:pyams_content.title}
 		</h1>
+		<div class="page-pubdate"
+			 tal:condition="settings.display_publication_date">
+			<span class="prefix">${i18n:settings.publication_date_prefix}</span>
+			${structure:provider:pyams_content.publication_date}
+		</div>
 		<div class="small">
 			<tal:var define="header tales:i18n(context, 'header', '')">${structure:tales:html(header)}</tal:var>
 		</div>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/common/portlet/templates/publication-date.pt	Mon Jun 22 18:31:49 2020 +0200
@@ -0,0 +1,1 @@
+${view.publication_date}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/common/portlet/templates/title-portlet.pt	Mon Jun 22 18:31:49 2020 +0200
@@ -0,0 +1,9 @@
+<tal:var define="settings view.settings">
+	${view.title}
+	<div class="page-pubdate"
+		 tal:condition="settings.display_publication_date">
+		<span class="prefix"
+			  tal:content="i18n:settings.publication_date_prefix" />
+		${structure:provider:pyams_content.publication_date}
+	</div>
+</tal:var>
--- a/src/pyams_default_theme/shared/common/portlet/title.py	Mon Jun 22 18:30:36 2020 +0200
+++ b/src/pyams_default_theme/shared/common/portlet/title.py	Mon Jun 22 18:31:49 2020 +0200
@@ -28,18 +28,20 @@
 
 
 @contentprovider_config(name='pyams_content.title', layer=IPyAMSUserLayer, view=Interface)
-@template_config(template='templates/title.pt', )
+@template_config(template='templates/title.pt')
 class SharedContentTitleProvider(ViewContentProvider):
     """Shared content title viewlet"""
 
     @property
     def title(self):
-        return self.request.registry.queryMultiAdapter((self.context, self.request), IContentTitle)
+        return self.request.registry.queryMultiAdapter((self.context, self.request),
+                                                       IContentTitle)
 
 
-@adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, ISharedContentTitlePortletSettings),
+@adapter_config(context=(IPortalContext, IPyAMSLayer, Interface,
+                         ISharedContentTitlePortletSettings),
                 provides=IPortletRenderer)
-@template_config(template='templates/title.pt', layer=IPyAMSLayer)
+@template_config(template='templates/title-portlet.pt', layer=IPyAMSLayer)
 class SharedContentTitlePortletRenderer(PortletRenderer):
     """Shared content title portlet renderer"""
 
@@ -47,4 +49,5 @@
 
     @property
     def title(self):
-        return self.request.registry.queryMultiAdapter((self.context, self.request), IContentTitle)
+        return self.request.registry.queryMultiAdapter((self.context, self.request),
+                                                       IContentTitle)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/common/portlet/workflow.py	Mon Jun 22 18:31:49 2020 +0200
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2015-2020 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+from babel import Locale, UnknownLocaleError
+from babel.dates import format_date
+from zope.interface import Interface
+
+from pyams_i18n.interfaces import INegotiator
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_template.template import template_config
+from pyams_utils.registry import get_utility
+from pyams_viewlet.viewlet import ViewContentProvider, contentprovider_config
+from pyams_workflow.interfaces import IWorkflowPublicationInfo
+
+
+@contentprovider_config(name='pyams_content.publication_date', layer=IPyAMSUserLayer,
+                        view=Interface)
+@template_config(template='templates/publication-date.pt')
+class SharedContentPublicationDataProvider(ViewContentProvider):
+    """Shared content publication date viewlet"""
+
+    @property
+    def publication_date(self):
+        info = IWorkflowPublicationInfo(self.context, None)
+        if info is None:
+            return ''
+        try:
+            locale = Locale(self.request.locale_name)
+        except UnknownLocaleError:
+            negotiator = get_utility(INegotiator)
+            locale = Locale(negotiator.server_language)
+        return format_date(info.visible_publication_date, format='long', locale=locale)
--- a/src/pyams_default_theme/shared/common/specificities.py	Mon Jun 22 18:30:36 2020 +0200
+++ b/src/pyams_default_theme/shared/common/specificities.py	Mon Jun 22 18:31:49 2020 +0200
@@ -14,9 +14,11 @@
 
 from pyams_content.features.renderer.interfaces import IContentRenderer
 from pyams_content.shared.common import IWfSharedContent
-from pyams_content.shared.common.interfaces.specificities import ISharedContentSpecificitiesParagraph
+from pyams_content.shared.common.interfaces.specificities import \
+    ISharedContentSpecificitiesParagraph
 from pyams_default_theme.features.renderer import BaseContentRenderer
-from pyams_default_theme.shared.common.interfaces import ICustomContentSpecificitiesParagraphRenderer
+from pyams_default_theme.shared.common.interfaces import \
+    ICustomContentSpecificitiesParagraphRenderer
 from pyams_skin.layer import IPyAMSLayer
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
@@ -29,7 +31,8 @@
 # Shared content specificities paragraph renderer
 #
 
-@adapter_config(name='default', context=(ISharedContentSpecificitiesParagraph, IPyAMSLayer), provides=IContentRenderer)
+@adapter_config(name='default', context=(ISharedContentSpecificitiesParagraph, IPyAMSLayer),
+                provides=IContentRenderer)
 @template_config(template='templates/specificities-paragraph.pt', layer=IPyAMSLayer)
 class SharedContentSpecificitiesParagraphRenderer(BaseContentRenderer):
     """Default shared content specificities paragraph renderer"""
@@ -43,10 +46,11 @@
         context = get_parent(self.context, IWfSharedContent)
         if context is not None:
             registry = self.request.registry
-            self.renderer = renderer = registry.queryMultiAdapter((context, self.request, self),
-                                                                  ICustomContentSpecificitiesParagraphRenderer)
+            self.renderer = renderer = registry.queryMultiAdapter(
+                (context, self.request, self), ICustomContentSpecificitiesParagraphRenderer)
             if renderer is not None:
                 renderer.update()
 
     def render(self):
-        return '' if self.renderer is None else super(SharedContentSpecificitiesParagraphRenderer, self).render()
+        return '' if self.renderer is None else \
+            super(SharedContentSpecificitiesParagraphRenderer, self).render()