Back to index

plone3  3.1.7
selectedTabs.py
Go to the documentation of this file.
00001 ## Script (Python) "selectedTabs"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=default_tab, obj=None, portal_tabs=[]
00008 ##title=
00009 ##
00010 
00011 from AccessControl import Unauthorized
00012 
00013 # we want to centralize where all tab selection is done
00014 # for now we will start off with the top tabs, 'portal_tabs'
00015 url_tool = context.portal_url
00016 plone_url = url_tool()
00017 request = context.REQUEST
00018 valid_actions = []
00019 
00020 url = request['URL']
00021 path = url[len(plone_url):]
00022 
00023 for action in portal_tabs:
00024     if not action['url'].startswith(plone_url):
00025         # In this case the action url is an external link. Then, we avoid 
00026         # issues (bad portal_tab selection) continuing with next action.
00027         continue
00028     action_path = action['url'][len(plone_url):]
00029     if not action_path.startswith('/'):
00030         action_path = '/' + action_path
00031     if path.startswith(action_path):
00032         # Make a list of the action ids, along with the path length for
00033         # choosing the longest (most relevant) path.
00034         valid_actions.append((len(action_path), action['id']))
00035 
00036 # Sort by path length, the longest matching path wins
00037 valid_actions.sort()
00038 if valid_actions:
00039     return {'portal':valid_actions[-1][1]}
00040 
00041 return {'portal':default_tab}