--- a/src/pyams_content/component/links/__init__.py Thu Jun 21 11:42:50 2018 +0200
+++ b/src/pyams_content/component/links/__init__.py Fri Jun 22 13:06:53 2018 +0200
@@ -9,6 +9,7 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
+from pyams_skin.layer import IPyAMSUserLayer
__docformat__ = 'restructuredtext'
@@ -35,7 +36,7 @@
from pyams_utils.registry import query_utility
from pyams_utils.request import check_request
from pyams_utils.traversing import get_parent
-from pyams_utils.url import absolute_url
+from pyams_utils.url import absolute_url, relative_url
from pyams_utils.vocabulary import vocabulary_config
from pyams_utils.zodb import volatile_property
from zope.interface import implementer
@@ -132,11 +133,11 @@
return 'oid://{0}'.format(self.reference)
def get_url(self, request=None, view_name=None):
- target = self.get_target(state=VISIBLE_STATES)
+ target = self.get_target()
if target is not None:
if request is None:
request = check_request()
- return absolute_url(target, request, view_name)
+ return relative_url(target, request, view_name=view_name)
else:
return ''
--- a/src/pyams_content/features/footer/skin/__init__.py Thu Jun 21 11:42:50 2018 +0200
+++ b/src/pyams_content/features/footer/skin/__init__.py Fri Jun 22 13:06:53 2018 +0200
@@ -19,6 +19,7 @@
from pyams_content.features.footer.interfaces import IFooterTarget, IFooterRenderer, IFooterSettings
from pyams_content.features.renderer.interfaces import HIDDEN_RENDERER_NAME
from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces.url import DISPLAY_CONTEXT
# import packages
from pyams_content.features.renderer.skin import BaseContentRenderer
@@ -35,7 +36,10 @@
def settings(self):
if self.settings_interface is None:
return None
- settings = IFooterSettings(self.context)
+ context = self.request.annotations.get(DISPLAY_CONTEXT)
+ if context is None:
+ context = self.context
+ settings = IFooterSettings(context)
while settings.inherit:
settings = IFooterSettings(settings.parent)
return settings.settings
--- a/src/pyams_content/features/header/skin/__init__.py Thu Jun 21 11:42:50 2018 +0200
+++ b/src/pyams_content/features/header/skin/__init__.py Fri Jun 22 13:06:53 2018 +0200
@@ -19,6 +19,7 @@
from pyams_content.features.header.interfaces import IHeaderTarget, IHeaderRenderer, IHeaderSettings
from pyams_content.features.renderer.interfaces import HIDDEN_RENDERER_NAME
from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces.url import DISPLAY_CONTEXT
# import packages
from pyams_content.features.renderer.skin import BaseContentRenderer
@@ -35,7 +36,10 @@
def settings(self):
if self.settings_interface is None:
return None
- settings = IHeaderSettings(self.context)
+ context = self.request.annotations.get(DISPLAY_CONTEXT)
+ if context is None:
+ context = self.context
+ settings = IHeaderSettings(context)
while settings.inherit:
settings = IHeaderSettings(settings.parent)
return settings.settings
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/skin/__init__.py Fri Jun 22 13:06:53 2018 +0200
@@ -0,0 +1,20 @@
+#
+# 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'
+
+
+# import standard library
+
+# import interfaces
+
+# import packages
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/skin/oid.py Fri Jun 22 13:06:53 2018 +0200
@@ -0,0 +1,56 @@
+#
+# 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'
+
+
+# import standard library
+
+# import interfaces
+from pyams_sequence.interfaces import ISequentialIntIds
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_utils.interfaces.url import DISPLAY_CONTEXT
+from pyams_workflow.interfaces import IWorkflow, IWorkflowVersions
+from zope.traversing.interfaces import ITraversable
+
+# import packages
+from pyams_sequence.utility import get_reference_target
+from pyams_utils.adapter import adapter_config, ContextRequestAdapter
+from pyams_utils.registry import get_utility
+from pyramid.exceptions import NotFound
+from zope.interface import Interface
+
+
+@adapter_config(name='oid', context=(Interface, IPyAMSUserLayer), provides=ITraversable)
+class OidTraverser(ContextRequestAdapter):
+ """++oid++ traverser"""
+
+ def traverse(self, name, furtherpath=None):
+ if not name:
+ raise NotFound()
+ if '::' in name:
+ oid, label = name.split('::', 1)
+ else:
+ oid = name
+ sequence = get_utility(ISequentialIntIds)
+ reference = sequence.get_full_oid(oid)
+ target = get_reference_target(reference)
+ if target is not None:
+ workflow = IWorkflow(target, None)
+ if workflow is not None:
+ versions = IWorkflowVersions(target).get_versions(workflow.published_states, sort=True)
+ if versions:
+ target = versions[-1]
+ if target is not None:
+ self.request.annotations[DISPLAY_CONTEXT] = self.context
+ return target
+ raise NotFound()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/skin/url.py Fri Jun 22 13:06:53 2018 +0200
@@ -0,0 +1,37 @@
+#
+# 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'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.shared.common import IWfSharedContent
+from pyams_sequence.interfaces import ISequentialIdInfo
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_utils.interfaces.url import IRelativeURL
+
+# import packages
+from pyams_utils.adapter import adapter_config, ContextRequestAdapter
+from pyams_utils.url import absolute_url
+
+
+@adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IRelativeURL)
+class SharedContentRelativeUrlAdapter(ContextRequestAdapter):
+ """Shared content relative URL adapter"""
+
+ def get_url(self, display_context=None, view_name=None, query=None):
+ return absolute_url(display_context, self.request,
+ '++oid++{0}::{1}.html'.format(
+ ISequentialIdInfo(self.context).get_base_oid().strip(),
+ self.context.content_url))
--- a/src/pyams_content/shared/common/zmi/workflow.py Thu Jun 21 11:42:50 2018 +0200
+++ b/src/pyams_content/shared/common/zmi/workflow.py Fri Jun 22 13:06:53 2018 +0200
@@ -832,7 +832,7 @@
(manager_restrictions.check_access(context, request=request)) and \
(not manager_restrictions.publication_checks):
return None
- if isinstance(form, PublicationForm):
+ if isinstance(form, PublicationRequestForm):
restrictions = IContributorRestrictions(context, None)
if restrictions is not None:
contributor_restrictions = restrictions.get_restrictions(principal_id)
--- a/src/pyams_content/shared/view/__init__.py Thu Jun 21 11:42:50 2018 +0200
+++ b/src/pyams_content/shared/view/__init__.py Fri Jun 22 13:06:53 2018 +0200
@@ -25,6 +25,7 @@
from pyams_content.features.review.interfaces import IReviewTarget
from pyams_content.shared.view.interfaces import IView, IWfView, IWfViewFactory, IViewQuery, \
IViewQueryParamsExtension, IViewQueryFilterExtension, VIEW_CONTENT_TYPE, VIEW_CONTENT_NAME, IViewSettings
+from pyams_utils.interfaces import ICacheKeyValue
from zope.intid.interfaces import IIntIds
from zope.lifecycleevent.interfaces import IObjectModifiedEvent
@@ -86,13 +87,12 @@
return list(content_types)
def get_results(self, context):
- intids = get_utility(IIntIds)
views_cache = get_cache(VIEWS_CACHE_REGION, VIEWS_CACHE_NAME)
if self.is_using_context:
- cache_key = VIEW_CONTEXT_CACHE_KEY.format(view=intids.queryId(self),
- context=intids.queryId(context))
+ cache_key = VIEW_CONTEXT_CACHE_KEY.format(view=ICacheKeyValue(self),
+ context=ICacheKeyValue(context))
else:
- cache_key = VIEW_CACHE_KEY.format(view=intids.queryId(self))
+ cache_key = VIEW_CACHE_KEY.format(ICacheKeyValue(self))
try:
results = views_cache.get_value(cache_key)
except KeyError:
@@ -101,6 +101,7 @@
if adapter is None:
adapter = registry.getAdapter(self, IViewQuery)
results = adapter.get_results(context, self.limit)
+ intids = get_utility(IIntIds)
views_cache.set_value(cache_key, [intids.queryId(item) for item in results])
logger.debug("Storing view items to cache key {0}".format(cache_key))
else:
--- a/src/pyams_content/skin/routes.py Thu Jun 21 11:42:50 2018 +0200
+++ b/src/pyams_content/skin/routes.py Fri Jun 22 13:06:53 2018 +0200
@@ -26,7 +26,7 @@
from pyams_catalog.query import CatalogResultSet
from pyams_content.workflow import VISIBLE_STATES
from pyams_utils.registry import get_utility
-from pyams_utils.url import absolute_url
+from pyams_utils.url import absolute_url, canonical_url
from pyramid.exceptions import NotFound
from pyramid.response import Response
from pyramid.view import view_config
@@ -51,12 +51,13 @@
params &= Any(catalog['workflow_state'], VISIBLE_STATES)
results = list(CatalogResultSet(CatalogQuery(catalog).query(params)))
if results:
+ response = Response()
+ response.status_code = 302
if view_name: # back-office access => last version
version = IWorkflowVersions(results[0]).get_last_versions()[0]
+ response.location = absolute_url(version, request, '/'.join(view_name))
else:
version = results[0]
- response = Response()
- response.status_code = 302
- response.location = absolute_url(version, request, '/'.join(view_name))
+ response.location = canonical_url(version, request)
return response
raise NotFound()