Moved custom routes to PyAMS default theme
authorThierry Florac <thierry.florac@onf.fr>
Thu, 08 Nov 2018 08:46:58 +0100
changeset 1069 abd11be23718
parent 1068 71efa4864cce
child 1070 ea0c7ac589c4
Moved custom routes to PyAMS default theme
src/pyams_content/include.py
src/pyams_content/skin/routes.py
--- a/src/pyams_content/include.py	Wed Nov 07 19:00:06 2018 +0100
+++ b/src/pyams_content/include.py	Thu Nov 08 08:46:58 2018 +0100
@@ -26,9 +26,6 @@
     # add custom twwen
     config.add_tween('pyams_content.features.redirect.tween.redirect_tween_factory', over=MAIN)
 
-    # add custom routes
-    config.add_route('oid_access', '/+/{oid}*view')
-
     # load registry components
     try:
         import pyams_zmi
--- a/src/pyams_content/skin/routes.py	Wed Nov 07 19:00:06 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-#
-# Copyright (c) 2008-2015 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 hypatia.interfaces import ICatalog
-from pyams_sequence.interfaces import ISequentialIntIds
-from pyams_workflow.interfaces import IWorkflowVersions
-
-# import packages
-from hypatia.catalog import CatalogQuery
-from hypatia.query import Eq, Any
-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, canonical_url
-from pyramid.exceptions import NotFound
-from pyramid.response import Response
-from pyramid.view import view_config
-
-
-@view_config(route_name='oid_access')
-def get_oid_access(request):
-    """Get direct access to given OID
-
-    This route can be used to get a direct access to a given content,
-    just by submitting an URL like /+/{oid}, where {oid} is the "short"
-    sequence OID.
-    """
-    oid = request.matchdict.get('oid')
-    if oid:
-        view_name = request.matchdict.get('view')
-        sequence = get_utility(ISequentialIntIds)
-        hex_oid = sequence.get_full_oid(oid)
-        catalog = get_utility(ICatalog)
-        params = Eq(catalog['oid'], hex_oid)
-        if not view_name:
-            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.location = canonical_url(version, request)
-            return response
-    raise NotFound()