vendor/CMF/1.6.3/CMFCore

view URLTool.py @ 2:4c712d7bd1d7

Added tag 1.6.3 for changeset 1babb9d61518
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Fri, 09 Sep 2011 12:44:00 +0200
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """ CMFCore portal_url tool.
15 $Id$
16 """
18 from AccessControl import ClassSecurityInfo
19 from Acquisition import aq_inner
20 from Acquisition import aq_parent
21 from Globals import DTMLFile
22 from Globals import InitializeClass
23 from OFS.SimpleItem import SimpleItem
25 from ActionProviderBase import ActionProviderBase
26 from permissions import ManagePortal
27 from permissions import View
28 from utils import _dtmldir
29 from utils import UniqueObject
31 from interfaces.portal_url import portal_url as IURLTool
34 class URLTool(UniqueObject, SimpleItem, ActionProviderBase):
35 """ CMF URL Tool.
36 """
38 __implements__ = (IURLTool, ActionProviderBase.__implements__)
40 id = 'portal_url'
41 meta_type = 'CMF URL Tool'
42 _actions = ()
44 security = ClassSecurityInfo()
45 security.declareObjectProtected(View)
47 manage_options = ( ActionProviderBase.manage_options
48 + ( {'label':'Overview',
49 'action':'manage_overview'}
50 ,
51 )
52 + SimpleItem.manage_options
53 )
55 #
56 # ZMI methods
57 #
58 security.declareProtected(ManagePortal, 'manage_overview')
59 manage_overview = DTMLFile('explainURLTool', _dtmldir)
61 #
62 # 'portal_url' interface methods
63 #
64 security.declarePublic('__call__')
65 def __call__(self, relative=0, *args, **kw):
66 """ Get by default the absolute URL of the portal.
67 """
68 return self.getPortalObject().absolute_url(relative=relative)
70 security.declarePublic('getPortalObject')
71 def getPortalObject(self):
72 """ Get the portal object itself.
73 """
74 return aq_parent( aq_inner(self) )
76 security.declarePublic('getRelativeContentPath')
77 def getRelativeContentPath(self, content):
78 """ Get the path for an object, relative to the portal root.
79 """
80 portal_path_length = len( self.getPortalObject().getPhysicalPath() )
81 content_path = content.getPhysicalPath()
82 return content_path[portal_path_length:]
84 security.declarePublic('getRelativeContentURL')
85 def getRelativeContentURL(self, content):
86 """ Get the URL for an object, relative to the portal root.
87 """
88 return '/'.join( self.getRelativeContentPath(content) )
90 security.declarePublic('getRelativeUrl')
91 getRelativeUrl = getRelativeContentURL
93 security.declarePublic('getPortalPath')
94 def getPortalPath(self):
95 """ Get the portal object's URL without the server URL component.
96 """
97 return '/'.join( self.getPortalObject().getPhysicalPath() )
99 InitializeClass(URLTool)