Back to index

plone3  3.1.7
plonifyActions.py
Go to the documentation of this file.
00001 ## Script (Python) "plonifyActions"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=template_id, actions=None, default_tab='view'
00008 ##
00009 
00010 from urllib import unquote
00011 here_url = context.absolute_url()
00012 site_properties=context.portal_properties.site_properties
00013 
00014 if actions is None:
00015     actions=context.portal_actions.listFilteredActionsFor()
00016 
00017 actionlist=[]
00018 if same_type(actions, {}):
00019     if context.getTypeInfo().getId() in \
00020         site_properties.getProperty('use_folder_tabs', ['Folder', 'Large Plone Folder', 'Plone Site']):
00021         actionlist=actions['folder']+actions['object']
00022     else:
00023         actionlist=actions['object']
00024 
00025 plone_actions=[]
00026 use_default=1
00027 
00028 request_url = context.REQUEST['ACTUAL_URL']
00029 request_url_path = request_url[len(here_url):]
00030 if request_url_path.startswith('/'):
00031     request_url_path = request_url_path[1:]
00032 
00033 for action in actionlist:
00034     item={'title':'',
00035           'id':'',
00036           'url':'',
00037           'selected':''}
00038 
00039     item['title']=action['title']
00040     item['id']=actionid=action['id']
00041 
00042     aurl=action['url'].strip()
00043     if not (aurl.startswith('http') or aurl.startswith('javascript')):
00044         item['url']='%s/%s'%(here_url,aurl)
00045     else:
00046         item['url']=aurl
00047 
00048     action_method=item['url'].split('/')[-1]
00049 
00050     # Action method may be a method alias: Attempt to resolve to a template.
00051     try:
00052         action_method=context.getTypeInfo().queryMethodID(action_method,
00053                                                           default = action_method)
00054     except AttributeError:
00055         # Don't raise if we don't have a CMF 1.5 FTI
00056         pass
00057 
00058     # we unquote since view names sometimes get escaped
00059     request_action = unquote( request_url_path )
00060     try:
00061         request_action=context.getTypeInfo().queryMethodID(request_action,
00062                                                            default = request_action)
00063     except AttributeError:
00064         # Don't raise if we don't have a CMF 1.5 FTI
00065         pass
00066     
00067     if action_method:
00068         if action_method==template_id or action_method == request_action:
00069             item['selected']=1
00070             use_default=0
00071 
00072     plone_actions.append(item)
00073 
00074 if use_default:
00075     for action in plone_actions:
00076         if action['id']==default_tab:
00077             action['selected']=1
00078             break
00079 
00080 first = ['folderContents']
00081 plone_actions.sort(lambda a, b: a['id'] in first and -1 or
00082                                 b['id'] in first and 1 or 0)
00083 
00084 return plone_actions