Back to index

plone3  3.1.7
get_permalink.py
Go to the documentation of this file.
00001 ## Script (Python) "get_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 the permalink url or None
00009 ##
00010 from Products.CMFCore.utils import getUtilityByInterfaceName
00011 from Products.CMFCore.utils import getToolByName
00012 
00013 # calculate the permalink if the uid handler tool exists, permalinks
00014 # are configured to be shown and the object is not folderish
00015 uidtool = getToolByName(context, 'portal_uidhandler', None)
00016 if uidtool is not None:
00017     ptool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IPropertiesTool')
00018     showPermalink = getattr(ptool, 'enable_permalink', None)
00019     isFolderish = getattr(context.aq_explicit, 'isPrincipiaFolderish', None)
00020     
00021     if showPermalink and not isFolderish:
00022         # returns the uid (generates one if necessary)
00023         utool = getToolByName(context, 'portal_url')
00024         uid = uidtool.register(context)
00025         url = "%s/permalink/%s" % (utool(), uid)
00026         return url