def fgProcessActionAdapters(self, errors, fields=None, REQUEST=None): if fields is None: fields = [fo for fo in self._getFieldObjects() if not IField.providedBy(fo)] if not errors: if self.getRawAfterValidationOverride(): # evaluate the override. # In case we end up traversing to a template, # we need to make sure we don't clobber # the expression context. self.getAfterValidationOverride() self.cleanExpressionContext(request=self.REQUEST) # get a list of adapters with no duplicates, retaining order adapters = [] for adapter in self.getRawActionAdapter(): if adapter not in adapters: adapters.append(adapter) for adapter in adapters: actionAdapter = getattr(self.aq_explicit, adapter, None) if actionAdapter is None: logger.warn( "Designated action adapter '%s' is missing; ignored. " "Removing it from active list." % adapter) self.toggleActionActive(adapter) else: # Now, see if we should execute it. # If using the 'finalise' workflow, only trigger # 'save data' adapters if self.getUseFinaliseButton() \ and 'form_finalise' not in REQUEST: if not IStatefulActionAdapter.providedBy(actionAdapter): # skip it continue # Check to see if execCondition exists and has contents if safe_hasattr(actionAdapter, 'execCondition') and \ len(actionAdapter.getRawExecCondition()): # evaluate the execCondition. # create a context for expression evaluation context = getExprContext(self, actionAdapter) doit = actionAdapter.getExecCondition( expression_context=context) else: # no reason not to go ahead doit = True if doit: result = actionAdapter.onSuccess(fields, \ REQUEST=REQUEST) if type(result) is type({}) and len(result): # return the dict, which hopefully uses # field ids or FORM_ERROR_MARKER for keys return result return errors
def testStateful(self): """ test stateful support """ # create a saver and add a record self.ff1.invokeFactory('FormSaveDataAdapter', 'saver') saver = self.ff1.saver self.ff1.setActionAdapter(['saver',]) # make sure we fit the interface self.assertTrue(IStatefulActionAdapter.providedBy(saver)) self.assertTrue(verifyClass(IStatefulActionAdapter, FormSaveDataAdapter)) self.assertTrue(verifyObject(IStatefulActionAdapter, saver)) # enable editing of submissions self.ff1.setAllowEditPrevious(True) # no data to start with self.assertFalse(self.ff1.hasExistingValues()) self.assertFalse(self.ff1.getExistingValue(self.ff1.topic)) request = FakeRequest(topic='test subject', replyto='*****@*****.**', comments='test comments') errors = self.ff1.fgvalidate(REQUEST=request) self.assertEqual(errors, {}) self.assertTrue(self.ff1.hasExistingValues()) self.assertEquals(self.ff1.getExistingValue(self.ff1.topic), 'test subject') # should also be able to directly query the saver userkey = self.ff1.getUserKey() self.assertTrue(saver.hasExistingValuesFor(userkey)) self.assertEquals(saver.getExistingValueFor(self.ff1.replyto, userkey), '*****@*****.**') self.logout() # fake user key - should not access to this userkey = '_fake_user_key_notused' self.assertRaises(Unauthorized, saver.hasExistingValuesFor, userkey) self.assertRaises(Unauthorized, saver.getExistingValueFor, self.ff1.topic, userkey)