src/pyams_default_theme/shared/common/url.py
changeset 399 e0bd4fb6c9a5
parent 357 91b2ec075f2b
equal deleted inserted replaced
398:1cfc6c4791ee 399:e0bd4fb6c9a5
    15 from pyams_content.shared.common import ISharedContent, IWfSharedContent
    15 from pyams_content.shared.common import ISharedContent, IWfSharedContent
    16 from pyams_sequence.interfaces import ISequentialIdInfo
    16 from pyams_sequence.interfaces import ISequentialIdInfo
    17 from pyams_skin.layer import IPyAMSUserLayer
    17 from pyams_skin.layer import IPyAMSUserLayer
    18 from pyams_utils.adapter import ContextRequestAdapter, adapter_config
    18 from pyams_utils.adapter import ContextRequestAdapter, adapter_config
    19 from pyams_utils.interfaces.url import ICanonicalURL, IRelativeURL
    19 from pyams_utils.interfaces.url import ICanonicalURL, IRelativeURL
    20 from pyams_utils.url import absolute_url, relative_url
    20 from pyams_utils.url import absolute_url, canonical_url, relative_url
    21 
    21 
    22 
    22 
    23 @adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=ICanonicalURL)
    23 @adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=ICanonicalURL)
    24 class WfSharedContentCanonicalUrlAdapter(ContextRequestAdapter):
    24 class WfSharedContentCanonicalUrlAdapter(ContextRequestAdapter):
    25     """Workflow managed shared content canonical URL adapter"""
    25     """Workflow managed shared content canonical URL adapter"""
    29                             '+/{0}::{1}{2}{3}'.format(
    29                             '+/{0}::{1}{2}{3}'.format(
    30                                 ISequentialIdInfo(self.context).get_base_oid().strip(),
    30                                 ISequentialIdInfo(self.context).get_base_oid().strip(),
    31                                 self.context.content_url,
    31                                 self.context.content_url,
    32                                 '/{}'.format(view_name) if view_name else '.html',
    32                                 '/{}'.format(view_name) if view_name else '.html',
    33                                 '?{}'.format(query) if query else ''))
    33                                 '?{}'.format(query) if query else ''))
       
    34 
       
    35 
       
    36 @adapter_config(context=(ISharedContent, IPyAMSUserLayer), provides=ICanonicalURL)
       
    37 class SharedContentCanonicalURLAdapter(ContextRequestAdapter):
       
    38     """Shared content canonical URL adapter"""
       
    39 
       
    40     def get_url(self, view_name=None, query=None):
       
    41         version = self.context.visible_version
       
    42         if version is not None:
       
    43             return canonical_url(version, self.request, view_name, query)
    34 
    44 
    35 
    45 
    36 @adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IRelativeURL)
    46 @adapter_config(context=(IWfSharedContent, IPyAMSUserLayer), provides=IRelativeURL)
    37 class WfSharedContentRelativeUrlAdapter(ContextRequestAdapter):
    47 class WfSharedContentRelativeUrlAdapter(ContextRequestAdapter):
    38     """Workflow managed shared content relative URL adapter"""
    48     """Workflow managed shared content relative URL adapter"""
    49 @adapter_config(context=(ISharedContent, IPyAMSUserLayer), provides=IRelativeURL)
    59 @adapter_config(context=(ISharedContent, IPyAMSUserLayer), provides=IRelativeURL)
    50 class SharedContentRelativeURLAdapter(ContextRequestAdapter):
    60 class SharedContentRelativeURLAdapter(ContextRequestAdapter):
    51     """Shared content relative URL adapter"""
    61     """Shared content relative URL adapter"""
    52 
    62 
    53     def get_url(self, display_context=None, view_name=None, query=None):
    63     def get_url(self, display_context=None, view_name=None, query=None):
    54         version = self.context.published_version
    64         version = self.context.visible_version
    55         if version is not None:
    65         if version is not None:
    56             return relative_url(version, self.request, display_context, view_name, query)
    66             return relative_url(version, self.request, display_context, view_name, query)