Back to index

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

List of all members.

Public Member Functions

def listActionTypes
def listFormValidators
def listFormActions
def listContextTypes
def manage_editFormValidators
def manage_addFormValidators
def manage_delFormValidators
def manage_editFormActions
def manage_addFormAction
def manage_delFormActions
def getNext
def getButton
def getValidators
def writableDefaults

Public Attributes

 actions
 validators

Static Public Attributes

tuple security = ClassSecurityInfo()
tuple manage_formActionsForm = PageTemplateFile('www/manage_formActionsForm', globals())
tuple manage_formValidatorsForm = PageTemplateFile('www/manage_formValidatorsForm', globals())

Private Member Functions

def _updateActions
def _updateValidators
def _base_notifyOfCopyTo
def _fixup_old_ids
def _base_manage_afterAdd
def _base_manage_afterClone
def _read_action_metadata
def _read_validator_metadata

Private Attributes

 _old_id
 _cloned_object_path

Detailed Description

Common functions for objects controlled by portal_form_controller

Definition at line 14 of file ControllerBase.py.


Member Function Documentation

def CMFFormController.ControllerBase.ControllerBase._base_manage_afterAdd (   self,
  object,
  container 
) [private]

Definition at line 67 of file ControllerBase.py.

00067 
00068     def _base_manage_afterAdd(self, object, container):
00069         old_id = getattr(self, '_old_id', None)
00070         if old_id:
00071             self._fixup_old_ids(old_id)
00072             delattr(self, '_old_id')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 73 of file ControllerBase.py.

00073 
00074     def _base_manage_afterClone(self, object):
00075         # clean up the old object
00076         cloned_object_path = getattr(self, '_cloned_object_path')
00077         cloned_object = self.getPhysicalRoot().unrestrictedTraverse(cloned_object_path)
00078         delattr(cloned_object, '_old_id')
00079         delattr(cloned_object, '_cloned_object_path')
00080         # clean up the new object
00081         delattr(self, '_cloned_object_path')

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFFormController.ControllerBase.ControllerBase._base_notifyOfCopyTo (   self,
  container,
  op = 0 
) [private]

Definition at line 51 of file ControllerBase.py.

00051 
00052     def _base_notifyOfCopyTo(self, container, op=0):
00053         self._old_id = self.getId()
00054         if op==0:  # copy
00055             self._cloned_object_path = self.getPhysicalPath()

Here is the caller graph for this function:

Definition at line 56 of file ControllerBase.py.

00056 
00057     def _fixup_old_ids(self, old_id):
00058         fc = getToolByName(self, 'portal_form_controller')
00059         id = self.getId()
00060         if old_id != id:
00061             if hasattr(aq_base(self), 'actions'):
00062                 self._updateActions(self.actions, old_id, id, move=1) # swap the ids for the default actions
00063                 self._updateActions(fc.actions, old_id, id, move=0) # copy the overrides
00064             if hasattr(aq_base(self), 'validators'):
00065                 self._updateValidators(self.validators, old_id, id, move=1) # swap the ids for the default validators
00066                 self._updateValidators(fc.validators, old_id, id, move=0) # copy the overrides

Here is the caller graph for this function:

def CMFFormController.ControllerBase.ControllerBase._read_action_metadata (   self,
  id,
  filepath 
) [private]

Definition at line 282 of file ControllerBase.py.

00282 
00283     def _read_action_metadata(self, id, filepath):
00284         self.actions = FormActionContainer()
00285 
00286         metadata = FSMetadata(filepath)
00287         cfg = CMFConfigParser()
00288         if os.path.exists(filepath + '.metadata'):
00289             cfg.read(filepath + '.metadata')
00290             _buttons_for_status = {}
00291 
00292             actions = metadata._getSectionDict(cfg, 'actions')
00293             if actions is None:
00294                 actions = {}
00295 
00296             for (k, v) in actions.items():
00297                 # action.STATUS.CONTEXT_TYPE.BUTTON = ACTION_TYPE:ACTION_ARG
00298                 component = k.split('.')
00299                 while len(component) < 4:
00300                     component.append('')
00301                 if component[0] != 'action':
00302                     raise ValueError, '%s: Format for .metadata actions is action.STATUS.CONTEXT_TYPE.BUTTON = ACTION_TYPE:ACTION_ARG (not %s)' % (filepath, k)
00303                 act = v.split(':',1)
00304                 while len(act) < 2:
00305                     act.append('')
00306 
00307                 context_type = component[2]
00308                 self.actions.set(FormAction(id, component[1], component[2], component[3], act[0], act[1]))
00309 
00310                 status_key = str(component[1])+'.'+str(context_type)
00311                 if _buttons_for_status.has_key(status_key):
00312                     _buttons_for_status[status_key].append(component[3])
00313                 else:
00314                     _buttons_for_status[status_key] = [component[3]]
00315 
00316             for (k, v) in _buttons_for_status.items():
00317                 if v and not '' in v:
00318                     sk = k.split('.')
00319                     status = sk[0]
00320                     content_type = sk[1]
00321                     if not status:
00322                         status = 'ANY'
00323                     if not content_type:
00324                         content_type = 'ANY'
00325                     log('%s: No default action specified for status %s, content type %s.  Users of IE can submit pages using the return key, resulting in no button in the REQUEST.  Please specify a default action for this case.' % (str(filepath), status, content_type))
00326                     

Here is the caller graph for this function:

def CMFFormController.ControllerBase.ControllerBase._read_validator_metadata (   self,
  id,
  filepath 
) [private]

Definition at line 327 of file ControllerBase.py.

00327 
00328     def _read_validator_metadata(self, id, filepath):
00329         self.validators = FormValidatorContainer()
00330 
00331         metadata = FSMetadata(filepath)
00332         cfg = CMFConfigParser()
00333         if os.path.exists(filepath + '.metadata'):
00334             cfg.read(filepath + '.metadata')
00335             _buttons_for_status = {}
00336 
00337             validators = metadata._getSectionDict(cfg, 'validators')
00338             if validators is None:
00339                 validators = {}
00340             for (k, v) in validators.items():
00341                 # validators.CONTEXT_TYPE.BUTTON = LIST
00342                 component = k.split('.')
00343                 while len(component) < 3:
00344                     component.append('')
00345                 if component[0] != 'validators':
00346                     raise ValueError, '%s: Format for .metadata validators is validators.CONTEXT_TYPE.BUTTON = LIST (not %s)' % (filepath, k)
00347 
00348                 context_type = component[1]
00349                 self.validators.set(FormValidator(id, component[1], component[2], v))
00350 
00351                 status_key = str(context_type)
00352                 if _buttons_for_status.has_key(status_key):
00353                     _buttons_for_status[status_key].append(component[2])
00354                 else:
00355                     _buttons_for_status[status_key] = [component[2]]
00356 
00357             for (k, v) in _buttons_for_status.items():
00358                 if v and not '' in v:
00359                     content_type = k
00360                     if not content_type:
00361                         content_type = 'ANY'
00362                     log('%s: No default validators specified for content type %s.  Users of IE can submit pages using the return key, resulting in no button in the REQUEST.  Please specify default validators for this case.' % (str(filepath), content_type))
00363 

Here is the caller graph for this function:

def CMFFormController.ControllerBase.ControllerBase._updateActions (   self,
  container,
  old_id,
  new_id,
  move 
) [private]
Copy action overrides stored in portal_form_controller from one 
object id to another

Definition at line 28 of file ControllerBase.py.

00028 
00029     def _updateActions(self, container, old_id, new_id, move):
00030         """Copy action overrides stored in portal_form_controller from one 
00031         object id to another"""
00032         actions = container.getFiltered(object_id=old_id)
00033         for a in actions:
00034             # if not container.match(new_id, a.getStatus(), a.getContextType(), a.getButton()):
00035             container.set(FormAction(new_id, a.getStatus(), a.getContextType(),
00036                            a.getButton(), a.getActionType(), a.getActionArg()))
00037         if move:
00038             for a in actions:
00039                 container.delete(a.getKey())
                

Here is the caller graph for this function:

def CMFFormController.ControllerBase.ControllerBase._updateValidators (   self,
  container,
  old_id,
  new_id,
  move 
) [private]
Copy validator overrides stored in portal_form_controller from one 
object id to another

Definition at line 40 of file ControllerBase.py.

00040 
00041     def _updateValidators(self, container, old_id, new_id, move):
00042         """Copy validator overrides stored in portal_form_controller from one 
00043         object id to another"""
00044         validators = container.getFiltered(object_id=old_id)
00045         for v in validators:
00046             # if not container.match(new_id, v.getContextType(), v.getButton()):
00047             container.set(FormValidator(new_id, v.getContextType(), v.getButton(), v.getValidators()))
00048         if move:
00049             for v in validators:
00050                 container.delete(v.getKey())
        

Here is the caller graph for this function:

def CMFFormController.ControllerBase.ControllerBase.getButton (   self,
  controller_state,
  REQUEST 
)

Definition at line 234 of file ControllerBase.py.

00234 
00235     def getButton(self, controller_state, REQUEST):
00236         buttons = []
00237         for k in REQUEST.form.keys():
00238             if k.startswith('form.button.'):
00239                 buttons.append(k)
00240         if buttons:
00241             # Clicking on an image button results in 2 button variables in REQUEST.form
00242             # (maybe 3),namely form.button.button_name.x, form.button.button_name.y, and
00243             # possibly form.button.button_name (not for IE, though)
00244             # If we see more than one key with the button prefix, try to handle sensibly.
00245             if len(buttons) > 1:
00246                 buttons.sort(lambda x, y: cmp(len(x), len(y)))
00247                 if buttons[0].endswith('.x') or buttons[0].endswith('.y'):
00248                     buttons[0] = buttons[0][:-2]
00249             button = buttons[0][len('form.button.'):]
00250             controller_state.setButton(button)
00251         return controller_state
00252 

Here is the caller graph for this function:

def CMFFormController.ControllerBase.ControllerBase.getNext (   self,
  controller_state,
  REQUEST 
)

Definition at line 187 of file ControllerBase.py.

00187 
00188     def getNext(self, controller_state, REQUEST):
00189         id = self.getId()
00190         status = controller_state.getStatus()
00191         context = controller_state.getContext()
00192         context_base = aq_base(context)
00193 
00194         context_type = getattr(context_base, 'portal_type', None)
00195         if context_type is None:
00196             context_type = getattr(context_base, '__class__', None)
00197             if context_type:
00198                 context_type = getattr(context_type, '__name__', None)
00199 
00200         button = controller_state.getButton()
00201         controller = getToolByName(aq_inner(self), 'portal_form_controller')
00202 
00203         next_action = None
00204         try:
00205             next_action = controller.getAction(id, status, context_type, button)
00206         except ValueError:
00207             pass
00208         if next_action is None:
00209             try:
00210                 if getattr(context_base, 'formcontroller_actions', None) is not None:
00211                     next_action = context.formcontroller_actions.match(id, status, context_type, button)
00212             except ValueError:
00213                 pass
00214         if next_action is None:
00215             try:
00216                 next_action = self.actions.match(id, status, context_type, button)
00217             except ValueError:
00218                 pass
00219             if next_action is None:
00220                 next_action = controller_state.getNextAction()
00221                 if next_action is None:
00222                     # default for failure is to traverse to the form
00223                     if status == 'failure':
00224                         next_action=FormAction(id, status, ANY_CONTEXT, ANY_BUTTON, 'traverse_to', 'string:%s' % id, controller)
00225                     if next_action is None:
00226                         metadata_actions = [str(a) for a in self.actions.getFiltered(object_id=id)]
00227                         zmi_actions = [str(a) for a in controller.actions.getFiltered(object_id=id)]
00228                         raise ValueError, 'No next action found for %s.%s.%s.%s\nMetadata actions:\n%s\n\nZMI actions:\n%s\n' % \
00229                             (id, status, context_type, button, '\n'.join(metadata_actions), '\n'.join(zmi_actions))
00230 
00231         REQUEST.set('controller_state', controller_state)
00232         return next_action.getAction()(controller_state)
00233 

Here is the caller graph for this function:

def CMFFormController.ControllerBase.ControllerBase.getValidators (   self,
  controller_state,
  REQUEST 
)

Definition at line 253 of file ControllerBase.py.

00253 
00254     def getValidators(self, controller_state, REQUEST):
00255         controller = getToolByName(self, 'portal_form_controller')
00256         context = controller_state.getContext()
00257         context_type = controller._getTypeName(context)
00258         button = controller_state.getButton()
00259 
00260         validators = None
00261         try:
00262             validators = controller.validators.match(self.id, context_type, button)
00263             if validators is not None:
00264                 return validators
00265         except ValueError:
00266             pass
00267         try:
00268             if hasattr(aq_base(context), 'formcontroller_validators'):
00269                 validators = context.formcontroller_validators.match(self.id, context_type, button)
00270                 if validators is not None:
00271                     return validators
00272         except ValueError:
00273             pass
00274         try:
00275             validators = self.validators.match(self.id, context_type, button)
00276             if validators is not None:
00277                 return validators
00278         except ValueError:
00279             pass
00280         return FormValidator(self.id, ANY_CONTEXT, ANY_BUTTON, [])
00281 

Here is the call graph for this function:

Here is the caller graph for this function:

Return a list of available action types.

Definition at line 83 of file ControllerBase.py.

00083 
00084     def listActionTypes(self):
00085         """Return a list of available action types."""
00086         return getToolByName(self, 'portal_form_controller').listActionTypes()

Here is the call graph for this function:

Return list of possible types for template context objects

Definition at line 110 of file ControllerBase.py.

00110 
00111     def listContextTypes(self):
00112         """Return list of possible types for template context objects"""
00113         return getToolByName(self, 'portal_form_controller').listContextTypes()
00114 

Here is the call graph for this function:

def CMFFormController.ControllerBase.ControllerBase.listFormActions (   self,
  override,
  kwargs 
)
Return a list of existing actions.  Actions can be filtered by
   specifying required attributes via kwargs

Definition at line 99 of file ControllerBase.py.

00099 
00100     def listFormActions(self, override, **kwargs):
00101         """Return a list of existing actions.  Actions can be filtered by
00102            specifying required attributes via kwargs"""
00103         controller = getToolByName(self, 'portal_form_controller')
00104         if override:
00105             return controller.actions.getFiltered(**kwargs)
00106         else:
00107             return self.actions.getFiltered(**kwargs)
00108 

Here is the call graph for this function:

def CMFFormController.ControllerBase.ControllerBase.listFormValidators (   self,
  override,
  kwargs 
)
Return a list of existing validators.  Validators can be filtered by
   specifying required attributes via kwargs

Definition at line 88 of file ControllerBase.py.

00088 
00089     def listFormValidators(self, override, **kwargs):
00090         """Return a list of existing validators.  Validators can be filtered by
00091            specifying required attributes via kwargs"""
00092         controller = getToolByName(self, 'portal_form_controller')
00093         if override:
00094             return controller.validators.getFiltered(**kwargs)
00095         else:
00096             return self.validators.getFiltered(**kwargs)
00097 

Here is the call graph for this function:

Process form action add form

Definition at line 164 of file ControllerBase.py.

00164 
00165     def manage_addFormAction(self, REQUEST):
00166         """Process form action add form"""
00167         controller = getToolByName(self, 'portal_form_controller')
00168         if REQUEST.form.get('override', 0):
00169             container = controller.actions
00170         else:
00171             container = self.actions
00172         controller._addFormAction(container, REQUEST)
00173         return REQUEST.RESPONSE.redirect(self.absolute_url()+'/manage_formActionsForm')
00174 

Here is the call graph for this function:

Process form validator add form

Definition at line 128 of file ControllerBase.py.

00128 
00129     def manage_addFormValidators(self, REQUEST):
00130         """Process form validator add form"""
00131         controller = getToolByName(self, 'portal_form_controller')
00132         if REQUEST.form.get('override', 0):
00133             container = controller.validators
00134         else:
00135             container = self.validators
00136         controller._addFormValidators(container, REQUEST)
00137         return REQUEST.RESPONSE.redirect(self.absolute_url()+'/manage_formValidatorsForm')
00138 

Here is the call graph for this function:

Process form action delete form

Definition at line 176 of file ControllerBase.py.

00176 
00177     def manage_delFormActions(self, REQUEST):
00178         """Process form action delete form"""
00179         controller = getToolByName(self, 'portal_form_controller')
00180         if REQUEST.form.get('override', 0):
00181             container = controller.actions
00182         else:
00183             container = self.actions
00184         controller._delFormActions(container, REQUEST)
00185         return REQUEST.RESPONSE.redirect(self.absolute_url()+'/manage_formActionsForm')
00186 

Here is the call graph for this function:

Process form validator delete form

Definition at line 140 of file ControllerBase.py.

00140 
00141     def manage_delFormValidators(self, REQUEST):
00142         """Process form validator delete form"""
00143         controller = getToolByName(self, 'portal_form_controller')
00144         if REQUEST.form.get('override', 0):
00145             container = controller.validators
00146         else:
00147             container = self.validators
00148         controller._delFormValidators(container, REQUEST)
00149         return REQUEST.RESPONSE.redirect(self.absolute_url()+'/manage_formValidatorsForm')
00150 

Here is the call graph for this function:

Process form action edit form

Definition at line 152 of file ControllerBase.py.

00152 
00153     def manage_editFormActions(self, REQUEST):
00154         """Process form action edit form"""
00155         controller = getToolByName(self, 'portal_form_controller')
00156         if REQUEST.form.get('override', 0):
00157             container = controller.actions
00158         else:
00159             container = self.actions
00160         controller._editFormActions(container, REQUEST)
00161         return REQUEST.RESPONSE.redirect(self.absolute_url()+'/manage_formActionsForm')
00162 

Here is the call graph for this function:

Process form validator edit form

Definition at line 116 of file ControllerBase.py.

00116 
00117     def manage_editFormValidators(self, REQUEST):
00118         """Process form validator edit form"""
00119         controller = getToolByName(self, 'portal_form_controller')
00120         if REQUEST.form.get('override', 0):
00121             container = controller.validators
00122         else:
00123             container = self.validators
00124         controller._editFormValidators(container, REQUEST)
00125         return REQUEST.RESPONSE.redirect(self.absolute_url()+'/manage_formValidatorsForm')
00126 

Here is the call graph for this function:

Can default actions and validators be modified?

Definition at line 365 of file ControllerBase.py.

00365 
00366     def writableDefaults(self):
00367         """Can default actions and validators be modified?"""
00368         return 1
00369 
00370 InitializeClass(ControllerBase)

Member Data Documentation

Definition at line 54 of file ControllerBase.py.

Definition at line 52 of file ControllerBase.py.

Definition at line 283 of file ControllerBase.py.

Definition at line 21 of file ControllerBase.py.

Definition at line 25 of file ControllerBase.py.

tuple CMFFormController.ControllerBase.ControllerBase.security = ClassSecurityInfo() [static]

Definition at line 17 of file ControllerBase.py.

Definition at line 328 of file ControllerBase.py.


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