Back to index

plone3  3.1.7
resolveuid.py
Go to the documentation of this file.
00001 ## Script (Python) "resolveuid"
00002 ##title=Retrieve an object using its UID
00003 ##bind container=container
00004 ##bind context=context
00005 ##bind namespace=
00006 ##bind script=script
00007 ##bind subpath=traverse_subpath
00008 ##parameters=
00009 # (reference_url is supposed to do the same thing, but is broken)
00010 from Products.CMFCore.utils import getToolByName
00011 from Products.PythonScripts.standard import html_quote
00012 from AccessControl import Unauthorized
00013 
00014 request = context.REQUEST
00015 response = request.RESPONSE
00016 
00017 try:
00018     uuid = traverse_subpath.pop(0)
00019 except:
00020     raise Unauthorized, context
00021 
00022 reference_tool = getToolByName(context, 'reference_catalog')
00023 obj = reference_tool.lookupObject(uuid)
00024 if not obj:
00025     hook = getattr(context, 'kupu_resolveuid_hook', None)
00026     if hook:
00027         obj = hook(uuid)
00028     if not obj:
00029         return response.notFoundError('''The link you followed appears to be broken''')
00030 
00031 if traverse_subpath:
00032     traverse_subpath.insert(0, obj.absolute_url())
00033     target = '/'.join(traverse_subpath)
00034 else:
00035     target = obj.absolute_url()
00036 
00037 if request.QUERY_STRING:
00038     target += '?' + request.QUERY_STRING
00039 return response.redirect(target, status=301)