Moved site features from PyAMS_content package
authorThierry Florac <tflorac@ulthar.net>
Wed, 07 Nov 2018 17:49:55 +0100
changeset 202 b1854f5a7be6
parent 201 ddbe98d86cc2
child 203 40bffafce365
Moved site features from PyAMS_content package
src/pyams_default_theme/shared/site/breadcrumb.py
src/pyams_default_theme/shared/site/folder.py
src/pyams_default_theme/shared/site/link.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/site/breadcrumb.py	Wed Nov 07 17:49:55 2018 +0100
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 2008-2018 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 pyams_content.shared.site.interfaces import ISiteContainer
+from pyams_i18n.interfaces import II18n
+from pyams_skin.interfaces.viewlet import IBreadcrumbItem
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_skin.viewlet.breadcrumb import BreadcrumbItem
+from pyams_utils.adapter import adapter_config
+
+
+@adapter_config(context=(ISiteContainer, IPyAMSUserLayer), provides=IBreadcrumbItem)
+class SiteContainerBreadcumbAdapter(BreadcrumbItem):
+    """Site container breadcrumb adapter"""
+
+    @property
+    def label(self):
+        return II18n(self.context).query_attribute('short_name', request=self.request)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/site/folder.py	Wed Nov 07 17:49:55 2018 +0100
@@ -0,0 +1,53 @@
+#
+# Copyright (c) 2008-2018 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 pyams_content.shared.site import ISiteElementNavigation
+from pyams_content.shared.site.interfaces import IContentSummaryInfo, ISiteFolder
+from pyams_i18n.interfaces import II18n
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_utils.adapter import ContextRequestAdapter, adapter_config
+from pyams_workflow.interfaces import IWorkflowPublicationInfo
+
+from pyams_content import _
+
+
+@adapter_config(context=(ISiteFolder, IPyAMSUserLayer), provides=ISiteElementNavigation)
+class SiteFolderNavigationAdapter(ContextRequestAdapter):
+    """Site folder navigation adapter"""
+
+    @property
+    def visible(self):
+        if not self.context.visible_in_list:
+            return False
+        return IWorkflowPublicationInfo(self.context).is_visible(self.request)
+
+
+@adapter_config(context=(ISiteFolder, IPyAMSUserLayer), provides=IContentSummaryInfo)
+class SiteFolderSummaryAdapter(ContextRequestAdapter):
+    """Site folder summary adapter"""
+
+    @property
+    def title(self):
+        i18n = II18n(self.context)
+        return i18n.query_attribute('navigation_title', request=self.request) or \
+               i18n.query_attribute('title', request=self.request)
+
+    @property
+    def header(self):
+        try:
+            return II18n(self.context).query_attribute('header', request=self.request)
+        except AttributeError:
+            return None
+
+    button_title = _("Consult folder")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/site/link.py	Wed Nov 07 17:49:55 2018 +0100
@@ -0,0 +1,61 @@
+#
+# Copyright (c) 2008-2018 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 pyams_content.shared.site.interfaces import IContentLink, IContentSummaryInfo
+from pyams_i18n.interfaces import II18n
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_utils.adapter import ContextRequestAdapter, adapter_config
+from pyams_utils.interfaces.url import IRelativeURL
+
+from pyams_content import _
+
+
+@adapter_config(context=(IContentLink, IPyAMSUserLayer), provides=IRelativeURL)
+def content_link_relative_url(context, request):
+    """Content link relative URL"""
+    target = context.get_target()
+    if target is not None:
+        return request.registry.queryMultiAdapter((target, request), IRelativeURL)
+
+
+@adapter_config(context=(IContentLink, IPyAMSUserLayer), provides=IContentSummaryInfo)
+class ContentLinkSummaryAdapter(ContextRequestAdapter):
+    """Content link summary adapter"""
+
+    target_info = None
+
+    def __init__(self, context, request):
+        super(ContentLinkSummaryAdapter, self).__init__(context, request)
+        target = self.target = self.context.target
+        if target is not None:
+            self.target_info = request.registry.queryMultiAdapter((target, request), IContentSummaryInfo)
+
+    @property
+    def title(self):
+        title = II18n(self.context).query_attribute('navigation_title', request=self.request)
+        if (title is None) and (self.target_info is not None):
+            title = self.target_info.title
+        return title
+
+    @property
+    def header(self):
+        if self.target_info is not None:
+            return self.target_info.header
+
+    @property
+    def button_title(self):
+        if self.target_info is not None:
+            return self.target_info.button_title
+        else:
+            return self.request.localizer.translate(_("Consult content"))