Back to index

plone3  3.1.7
Public Member Functions
CMFFormController.Actions.TraverseToAction.TraverseToAction Class Reference
Inheritance diagram for CMFFormController.Actions.TraverseToAction.TraverseToAction:
Inheritance graph
[legend]
Collaboration diagram for CMFFormController.Actions.TraverseToAction.TraverseToAction:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __call__

Detailed Description

Definition at line 13 of file TraverseToAction.py.


Member Function Documentation

Definition at line 15 of file TraverseToAction.py.

00015 
00016     def __call__(self, controller_state):
00017         action = self.getArg(controller_state)
00018         action_url = None
00019         haveAction = False
00020 
00021         context = controller_state.getContext()
00022         actions_tool = getToolByName(context, 'portal_actions')
00023         fti = context.getTypeInfo()
00024         REQUEST = getattr(context, 'REQUEST', None)
00025 
00026         try:
00027             # Test to see if the action is defined in the FTI as an object or
00028             # folder action
00029             action_ob = fti.getActionObject('object/'+action)
00030             if action_ob is None:
00031                 action_ob = fti.getActionObject('folder/'+action)
00032             # Use portal actions here so we have a full expression context
00033             ec = actions_tool._getExprContext(context)
00034             actiondict = action_ob.getAction(ec)
00035             haveAction = True
00036         except (ValueError, AttributeError):
00037             actions = actions_tool.listFilteredActionsFor(
00038                                                 controller_state.getContext())
00039             # flatten the actions as we don't care where they are
00040             actions = reduce(lambda x,y,a=actions:  x+a[y], actions.keys(), [])
00041             for actiondict in actions:
00042                 if actiondict['id'] == action:
00043                     haveAction = True
00044                     break
00045         # For traversal, our 'url' must be a traversable path
00046         if haveAction:
00047             action_url = actiondict['url'].strip()
00048             url_parts = urlsplit(action_url)
00049             # Check to see if we have a protocol, if so convert to a path,
00050             # otherwise make the assumption that we are dealing with a
00051             # physical path
00052             if url_parts[0] and REQUEST is not None:
00053                 action_url = '/'.join(REQUEST.physicalPathFromURL(action_url))
00054             else:
00055                 action_url = url_parts[2]
00056         else:
00057             raise ValueError, 'No %s action found for %s' % (action, controller_state.getContext().getId())
00058 
00059         # If we have CMF 1.5, the actual action_url may be hidden behind a method
00060         # alias. Attempt to resolve this
00061         try:
00062             if action_url:
00063                 # If our url is a path, then we need to see if it contains the
00064                 # path to the current object, if so we need to check if the
00065                 # remaining path element is a method alias
00066                 possible_alias = action_url
00067                 current_path = '/'.join(context.getPhysicalPath())
00068                 if possible_alias.startswith(current_path):
00069                     possible_alias = possible_alias[len(current_path)+1:]
00070                 if possible_alias:
00071                     action_url = fti.queryMethodID(possible_alias,
00072                                                    default = action_url,
00073                                                    context = context)
00074         except AttributeError:
00075             # Don't raise if we don't have CMF 1.5
00076             pass
00077 
00078         # XXX: Is there a better way to check this?
00079         if not action_url.startswith('string:'):
00080             action_url = 'string:%s' % (action_url,)
00081         return TraverseTo.TraverseTo(action_url)(controller_state)
00082 
00083 registerFormAction('traverse_to_action',
00084                    factory,
00085                    'Traverse to the action specified in the argument (a TALES expression) for the current context object (e.g. string:view)')

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: