--- a/src/pyams_default_theme/shared/site/__init__.py Tue Oct 30 12:32:31 2018 +0100
+++ b/src/pyams_default_theme/shared/site/__init__.py Mon Nov 05 13:21:33 2018 +0100
@@ -12,14 +12,19 @@
__docformat__ = 'restructuredtext'
+from pyramid.httpexceptions import HTTPSeeOther
from zope.interface import Interface
-from pyams_content.shared.site.interfaces import ISiteFolder, ISiteManager
+from pyams_content.shared.site.interfaces import FOLDER_REDIRECT_DISPLAY_MODE, ISiteFolder, ISiteManager
from pyams_i18n.interfaces import II18n
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_portal.views import PortalContextIndexPage, PortalContextPreviewPage
from pyams_skin.interfaces.metas import IHTMLContentMetas
from pyams_skin.layer import IPyAMSUserLayer
from pyams_skin.metas import ContentMeta, HTMLTagMeta
from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+from pyams_utils.url import relative_url
@adapter_config(name='title', context=(ISiteManager, IPyAMSUserLayer, Interface), provides=IHTMLContentMetas)
@@ -38,3 +43,27 @@
description = i18n.query_attribute('header', request=self.request)
if description:
yield ContentMeta('description', description)
+
+
+@pagelet_config(name='', context=ISiteFolder, layer=IPyAMSUserLayer)
+class SiteFolderIndexPage(PortalContextIndexPage):
+ """Site folder index page"""
+
+ def __call__(self, **kwargs):
+ if self.context.navigation_mode == FOLDER_REDIRECT_DISPLAY_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(SiteFolderIndexPage, self).__call__(**kwargs)
+
+
+@pagelet_config(name='preview.html', context=ISiteFolder, layer=IPyAMSUserLayer, permission=VIEW_SYSTEM_PERMISSION)
+class SiteFolderPreviewPage(PortalContextPreviewPage):
+ """Site folder preview page"""
+
+ def __call__(self, **kwargs):
+ if self.context.navigation_mode == FOLDER_REDIRECT_DISPLAY_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(SiteFolderPreviewPage, self).__call__(**kwargs)