Back to index

plone3  3.1.7
permalink.py
Go to the documentation of this file.
00001 ## Script (Python) "permalink"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=
00008 ##title=Returns an object by unique id
00009 ##
00010 from Products.CMFCore.utils import getUtilityByInterfaceName
00011 
00012 subpath = traverse_subpath[0]
00013 uid_handler=getUtilityByInterfaceName('Products.CMFUid.interfaces.UniqueIDHandler')
00014 
00015 # appending 'isAvailable' instead of a unique id returns if
00016 # the site permalink feature is available.
00017 if str(subpath).strip() == 'isAvailable':
00018     # no permalink feature without an uid handler tool being installed
00019     if uid_handler is None:
00020         return '0'
00021     ptool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IPropertiesTool')
00022     isAvailable = getattr(ptool, 'enable_permalink', 0)
00023     return str(int(isAvailable))
00024 
00025 obj = uid_handler.getObject(subpath)
00026 
00027 ti = obj.getTypeInfo()
00028 method_id = ti and ti.queryMethodID('view', context=self)
00029 if method_id:
00030     return getattr(obj, method_id)()
00031 return obj()