Logo Search packages:      
Sourcecode: zope-cmfplone version File versions

def zope-cmfplone-2.0.4::FormTool::FormValidator::_validate (   self,
  context,
  REQUEST,
  trace 
) [private]

Execute validators on the validation stack then sets up the REQUEST and returns a status.
   Places a dictionary of errors in the REQUEST that is accessed via REQUEST[FormTool.error_key]

Definition at line 290 of file FormTool.py.

00290                                                 :
        """Execute validators on the validation stack then sets up the REQUEST and returns a status.
           Places a dictionary of errors in the REQUEST that is accessed via REQUEST[FormTool.error_key]
        """
        try:
            errors = {}
            # default return value if the validator list is empty
            status = 'success'
            kwargs = {}
            for validator in self.validators:
                trace.append('Invoking %s' % validator)
                v = context.restrictedTraverse(validator, default=None)
                if v is None:
                    raise KeyError("Unable to find validator '%s' in context '%s'.  Check your skins path." % (validator, str(context)))

                # handle CMFFormController validators properly
                if getattr(v, 'is_validator', 0):
                    # get a controller_state object and populate it
                    form_controller = getToolByName(context, 'portal_form_controller')
                    try:
                        controller_state = form_controller.getState(context, 1)
                    except ValueError:
                        controller_state = ControllerState()
                        controller_state.set(context=context)
                        controller_state.setButton(None)
                        for k in REQUEST.keys():
                            if k.startswith('form.button.'):
                                controller_state.setButton(k[len('form.button.'):])
                                break
                    controller_state.setStatus(REQUEST.get('validation_status', 'success'))
                    controller_state.setErrors(REQUEST.get('errors', {}))
                    # XXX this is a bit of a hack -- lots of REQUEST keys could be
                    # controller_state kwargs, but we don't know which ones.
                    # portal_status_message is a common one.
                    msg = REQUEST.get('portal_status_message', None)
                    if msg:
                        controller_state.setKwargs({'portal_status_message':msg})
                    REQUEST.set('controller_state', controller_state)
                    if controller_state.hasValidated(validator):
                        continue
                    try:
                        controller_state = mapply(v, REQUEST.args, REQUEST,
                                                  call_object, 1, missing_name, dont_publish_class,
                                                  REQUEST, bind=1)
                        controller_state._addValidator(validator)
                    except ValidationError, e:
                        # if a validator raises a ValidatorException, execution of
                        # validators is halted and the controller_state is set to
                        # the controller_state embedded in the exception
                        controller_state = e.controller_state
                        state_class = getattr(controller_state, '__class__', None)
                        if state_class != ControllerState:
                            raise Exception, 'Bad ValidationError state (type = %s)' % str(state_class)
                        status = controller_state.getStatus()
                        kwargs = controller_state.getKwargs()
                        kwargs['errors'] = controller_state.getErrors()
                        new_context = controller_state.getContext()
                        break
                    state_class = getattr(controller_state, '__class__', None)
                    if state_class != ControllerState:
                        raise Exception, 'Bad validator return type from validator %s (%s)' % (str(v), str(state_class))

                    status = controller_state.getStatus()
                    kwargs = controller_state.getKwargs()
                    kwargs['errors'] = controller_state.getErrors()
                    new_context = controller_state.getContext()

                else:
                    script_status = mapply(v, REQUEST.args, REQUEST,
                                           call_object, 1, missing_name, dont_publish_class,
                                           REQUEST, bind=1)

                    # The preferred return type for scripts will
                    # eventually be an object.  Until then, preserve
                    # compatibility with 1.0 alpha 4

                    if type(script_status) == type(()):
                        (status, errors, kwargs) = script_status
                        kwargs['errors'] = errors
                        script_status = ScriptStatus(status, kwargs, None)

                        # disable deprecation warning for now
                        # log_deprecated('Validator \'%s\' uses a return
                        # signature that has been marked for deprecation.
                        # Validators should return a ScriptStatus object.'
                        # % validator)

                    status = script_status.status
                    kwargs = script_status.kwargs
                    new_context = script_status.new_context

                self.REQUEST.set('validation_status', status)
                for key in kwargs.keys():
                    self.REQUEST.set(key, kwargs[key])
                trace.append('\t -> (%s, %s)' % (status, str(kwargs)))
                if new_context is not None:
                    context = new_context
                    trace.append("\t context changed to '%s'" % str(context))
            trace.append('Validation returned (%s, %s)' % (status, str(kwargs)))
            return (status, kwargs, trace)
        except ConflictError:
            raise
        except:
            nav = getToolByName(self, 'portal_navigation')
            nav.logTrace(trace)
            raise


    security.declarePublic('log')
    def log(self, msg, loc=None):


Generated by  Doxygen 1.6.0   Back to index