Handle navigation mode on sites and hubs managers
authorThierry Florac <tflorac@ulthar.net>
Mon, 01 Feb 2021 13:36:23 +0100
changeset 547 ac39aec467ea
parent 546 4d60dd445586
child 548 356a54a98a51
Handle navigation mode on sites and hubs managers
src/pyams_default_theme/shared/site/manager.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/site/manager.py	Mon Feb 01 13:36:23 2021 +0100
@@ -0,0 +1,52 @@
+#
+# Copyright (c) 2015-2021 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.
+#
+
+"""PyAMS_*** module
+
+"""
+
+__docformat__ = 'restructuredtext'
+
+from pyramid.httpexceptions import HTTPSeeOther
+
+from pyams_content.shared.site.interfaces import SITE_CONTAINER_REDIRECT_MODE, ISiteManager
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_portal.views import PortalContextIndexPage, PortalContextPreviewPage
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+from pyams_utils.url import relative_url
+
+
+@pagelet_config(name='', context=ISiteManager, layer=IPyAMSUserLayer)
+class SiteManagerIndexPage(PortalContextIndexPage):
+    """Site manager index page"""
+
+    def __call__(self, **kwargs):
+        if self.context.navigation_mode == SITE_CONTAINER_REDIRECT_MODE:
+            target = next(self.context.get_visible_items(self.request), None)
+            if target is not None:
+                return HTTPSeeOther(relative_url(target, request=self.request))
+        return super().__call__(**kwargs)
+
+
+@pagelet_config(name='preview.html', context=ISiteManager, layer=IPyAMSUserLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+class SiteManagerPreviewPage(PortalContextPreviewPage):
+    """Site manager preview page"""
+
+    def __call__(self, **kwargs):
+        if self.context.navigation_mode == SITE_CONTAINER_REDIRECT_MODE:
+            target = next(self.context.get_visible_items(self.request), None)
+            if target is not None:
+                return HTTPSeeOther(relative_url(target, request=self.request,
+                                                 view_name='preview.html'))
+        return super().__call__(**kwargs)