Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Static Private Attributes
CMFFormController.Actions.BaseFormAction.BaseFormAction Class Reference

List of all members.

Public Member Functions

def __init__
def __call__
def getArg
def combineArgs
def updateQuery

Static Public Attributes

tuple security = ClassSecurityInfo()
 expression = None

Static Private Attributes

 __implements__ = IFormAction,

Detailed Description

Definition at line 15 of file BaseFormAction.py.


Constructor & Destructor Documentation

Definition at line 24 of file BaseFormAction.py.

00024 
00025     def __init__(self, arg=None):
00026         if arg is None:
00027             log('No argument specified for action.  This means that some of your CMFFormController actions may have been corrupted.  You may be able to fix them by editing the actions in question via the Actions tab and re-saving them.')
00028         else:
00029             try:
00030                 self.expression = Expression(arg)
00031             except:
00032                 raise CompilerError, 'Bad action expression %s' % str(arg)
00033 


Member Function Documentation

Definition at line 34 of file BaseFormAction.py.

00034 
00035     def __call__(self, controller_state):
00036         raise NotImplementedError
00037 

Here is the caller graph for this function:

Utility method that takes a URL, parses its existing query string,
and combines the resulting dict with kwargs

Definition at line 82 of file BaseFormAction.py.

00082 
00083     def combineArgs(self, url, kwargs):
00084         """Utility method that takes a URL, parses its existing query string,
00085         and combines the resulting dict with kwargs"""
00086         import urlparse
00087         import cgi
00088 
00089         # parse the existing URL
00090         parsed_url = list(urlparse.urlparse(url))
00091         # get the existing query string
00092         qs = parsed_url[4]
00093         # parse the query into a dict
00094         d = cgi.parse_qs(qs, 1)
00095         # update with stuff from kwargs
00096         for k, v in kwargs.items():
00097             if isinstance(v, unicode):
00098                 v = v.encode(URL_ENCODING)
00099             d[k] = [v] # put in a list to be consistent with parse_qs
00100         # parse_qs behaves a little unexpectedly -- all query string args
00101         # are represented as lists.  I think the reason is so that you get
00102         # consistent behavior for things like http://myurl?a=1&a=2&a=3
00103         # For this case parse_qs returns d['a'] = ['1','2','3']
00104         # However, that means that http://myurl?a=1 comes back as d['a']=['1']
00105         # unmunge some of parse_qs's weirdness
00106         dnew = {}
00107         for k, v in d.items():
00108             if v and len(v) == 1:
00109                 dnew[k] = v[0]
00110             else:
00111                 dnew[k] = v
00112         return dnew
00113 

Here is the caller graph for this function:

Generate an expression context for the TALES expression used as
the argument to the action and evaluate the expression.

Definition at line 38 of file BaseFormAction.py.

00038 
00039     def getArg(self, controller_state):
00040         """Generate an expression context for the TALES expression used as
00041         the argument to the action and evaluate the expression."""
00042         context = controller_state.getContext()
00043 
00044         portal = getToolByName(context, 'portal_url').getPortalObject()
00045         portal_membership = getToolByName(portal, 'portal_membership')
00046 
00047         if context is None or not hasattr(context, 'aq_base'):
00048             folder = portal
00049         else:
00050             folder = context
00051             # Search up the containment hierarchy until we find an
00052             # object that claims to be a folder.
00053             while folder is not None:
00054                 if getattr(aq_base(folder), 'isPrincipiaFolderish', 0):
00055                     # found it.
00056                     break
00057                 else:
00058                     folder = aq_parent(aq_inner(folder))
00059 
00060         object_url = context.absolute_url()
00061 
00062         if portal_membership.isAnonymousUser():
00063             member = None
00064         else:
00065             member = portal_membership.getAuthenticatedMember()
00066         data = {
00067             'object_url':   object_url,
00068             'folder_url':   folder.absolute_url(),
00069             'portal_url':   portal.absolute_url(),
00070             'object':       context,
00071             'folder':       folder,
00072             'portal':       portal,
00073             'nothing':      None,
00074             'request':      getattr( context, 'REQUEST', None ),
00075             'modules':      SecureModuleImporter,
00076             'member':       member,
00077             'state':        controller_state,
00078             }
00079         exprContext = getEngine().getContext(data)
00080         return self.expression(exprContext)
00081 

Here is the call graph for this function:

Here is the caller graph for this function:

Utility method that takes a URL, parses its existing query string,
url encodes
and updates the query string using the values in kwargs

Definition at line 114 of file BaseFormAction.py.

00114 
00115     def updateQuery(self, url, kwargs):
00116         """Utility method that takes a URL, parses its existing query string,
00117         url encodes
00118         and updates the query string using the values in kwargs"""
00119         d = self.combineArgs(url, kwargs)
00120         
00121         import urlparse
00122 
00123         # parse the existing URL
00124         parsed_url = list(urlparse.urlparse(url))
00125             
00126         # re-encode the string
00127         # We use ZTUtils.make_query here because it
00128         # does Zope-specific marshalling of lists,
00129         # dicts, integers and DateTime.
00130         # XXX *Normal* people should not be affected by this.
00131         # but one can argue about the need of using
00132         # standard query encoding instead for non-Zope
00133         # destination urls.
00134         parsed_url[4] = make_query(**d)
00135         # rebuild the URL
00136         return urlparse.urlunparse(parsed_url)
00137 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 16 of file BaseFormAction.py.

Definition at line 22 of file BaseFormAction.py.

Definition at line 18 of file BaseFormAction.py.


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