def teardown(self):
        for action in config_ready._keep_on_reset[:]:
            default_object = im_self(action)
            if default_object and isinstance(default_object, TemporaryGlobalConfigurable):
                config_ready._keep_on_reset.remove(action)

        config_ready._reset()
    def teardown(self):
        for action in config_ready._keep_on_reset[:]:
            default_object = im_self(action)
            if default_object and isinstance(default_object,
                                             TemporaryGlobalConfigurable):
                config_ready._keep_on_reset.remove(action)

        config_ready._reset()
Beispiel #3
0
    def _handle_validation_errors(cls, controller, remainder, params, exception, tgl=None):
        """Handle validation errors.

        Sets up validation status and error tracking
        to assist generating a form with given values
        and the validation failure messages.

        The error handler in decoration.validation.error_handler is called.
        If an error_handler isn't given, the original controller is used
        as the error handler instead.

        """
        if tgl is None: #pragma: no cover
            #compatibility with old code that didn't pass request locals explicitly
            tgl = tg.request.environ['tg.locals']

        req = tgl.request

        validation_status = req.validation
        validation_status['exception'] = exception

        if isinstance(exception, _Tw2ValidationError):
            #Fetch all the children and grandchildren of a widget
            widget = exception.widget
            widget_children = _navigate_tw2form_children(widget.child)

            errors = dict((child.key, child.error_msg) for child in widget_children)
            validation_status['errors'] = errors
            validation_status['values'] = widget.child.value
        elif isinstance(exception, TGValidationError):
            validation_status['errors'] = exception.error_dict
            validation_status['values'] = exception.value
        else:
            # Most Invalid objects come back with a list of errors in the format:
            #"fieldname1: error\nfieldname2: error"
            error_list = exception.__str__().split('\n')
            for error in error_list:
                field_value = map(strip_string, error.split(':', 1))

                #if the error has no field associated with it,
                #return the error as a global form error
                if len(field_value) == 1:
                    validation_status['errors']['_the_form'] = field_value[0]
                    continue

                validation_status['errors'][field_value[0]] = field_value[1]

            validation_status['values'] = getattr(exception, 'value', {})

        deco = controller.decoration
        validation_status['error_handler'] = error_handler = deco.validation.error_handler
        if error_handler is None:
            validation_status['error_handler'] = error_handler = controller
            output = error_handler(*remainder, **dict(params))
        else:
            output = error_handler(im_self(controller), *remainder, **dict(params))

        return error_handler, output
Beispiel #4
0
    def _process_validation_errors(cls, controller, remainder, params,
                                   exception, context):
        """Process validation errors.

        Sets up validation status and error tracking
        to assist generating a form with given values
        and the validation failure messages.

        The error handler in decoration.validation.error_handler resolved
        and returned to be called as a controller.
        If an error_handler isn't given, the original controller is returned instead.

        """
        req = context.request

        validation_status = req.validation
        validation_status['exception'] = exception

        if isinstance(exception, _Tw2ValidationError):
            #Fetch all the children and grandchildren of a widget
            widget = exception.widget
            widget_children = _navigate_tw2form_children(widget.child)

            errors = dict((child.compound_key, child.error_msg)
                          for child in widget_children)
            validation_status['errors'] = errors
            validation_status['values'] = widget.child.value
        elif isinstance(exception, TGValidationError):
            validation_status['errors'] = exception.error_dict
            validation_status['values'] = exception.value
        else:
            # Most Invalid objects come back with a list of errors in the format:
            #"fieldname1: error\nfieldname2: error"
            error_list = exception.__str__().split('\n')
            for error in error_list:
                field_value = list(map(strip_string, error.split(':', 1)))

                #if the error has no field associated with it,
                #return the error as a global form error
                if len(field_value) == 1:
                    validation_status['errors']['_the_form'] = field_value[0]
                    continue

                validation_status['errors'][field_value[0]] = field_value[1]

            validation_status['values'] = getattr(exception, 'value', {})

        deco = controller.decoration

        error_handler = deco.validation.error_handler
        if error_handler is None:
            error_handler = default_im_func(controller)

        validation_status['error_handler'] = error_handler
        return im_self(controller), error_handler
Beispiel #5
0
    def _handle_validation_errors(self,
            controller, remainder, params, exception):
        """Handle validation errors.

        Sets up tg.tmpl_context.form_values
        and tg.tmpl_context.form_errors
        to assist generating a form with given values
        and the validation failure messages.

        The error handler in decoration.validation.error_handler is called.
        If an error_handler isn't given, the original controller is used
        as the error handler instead.

        """
        tmpl_context = tg.tmpl_context
        tmpl_context.validation_exception = exception
        tmpl_context.form_errors = {}

        if isinstance(exception, _Tw2ValidationError):
            #Fetch all the children and grandchildren of a widget
            widget = exception.widget
            widget_children = _navigate_tw2form_children(widget.child)

            errors = [(child.key, child.error_msg) for child in widget_children]
            tmpl_context.form_errors.update(errors)
            tmpl_context.form_values = widget.child.value
        elif isinstance(exception, TGValidationError):
            tmpl_context.form_errors = exception.error_dict
            tmpl_context.form_values = exception.value
        else:
            # Most Invalid objects come back with a list of errors in the format:
            #"fieldname1: error\nfieldname2: error"
            error_list = exception.__str__().split('\n')
            for error in error_list:
                field_value = map(strip_string, error.split(':', 1))

                #if the error has no field associated with it,
                #return the error as a global form error
                if len(field_value) == 1:
                    tmpl_context.form_errors['_the_form'] = field_value[0]
                    continue

                tmpl_context.form_errors[field_value[0]] = field_value[1]

            tmpl_context.form_values = getattr(exception, 'value', {})

        error_handler = controller.decoration.validation.error_handler
        if error_handler is None:
            error_handler = controller
            output = error_handler(*remainder, **dict(params))
        else:
            output = error_handler(im_self(controller), *remainder, **dict(params))

        return error_handler, output
Beispiel #6
0
    def _process_validation_errors(cls, controller, remainder, params, exception, context):
        """Process validation errors.

        Sets up validation status and error tracking
        to assist generating a form with given values
        and the validation failure messages.

        The error handler in decoration.validation.error_handler resolved
        and returned to be called as a controller.
        If an error_handler isn't given, the original controller is returned instead.

        """
        req = context.request

        validation_status = req.validation
        validation_status.exception = exception

        if isinstance(exception, _Tw2ValidationError):
            # Fetch all the children and grandchildren of a widget
            widget = exception.widget
            widget_children = _navigate_tw2form_children(widget.child)

            errors = dict((child.compound_key, child.error_msg) for child in widget_children)
            validation_status.errors = errors
            validation_status.values = widget.child.value
        elif isinstance(exception, TGValidationError):
            validation_status.errors = exception.error_dict
            validation_status.values = exception.value
        else:
            # Most Invalid objects come back with a list of errors in the format:
            # "fieldname1: error\nfieldname2: error"
            error_list = exception.__str__().split('\n')
            for error in error_list:
                field_value = list(map(strip_string, error.split(':', 1)))

                #if the error has no field associated with it,
                #return the error as a global form error
                if len(field_value) == 1:
                    validation_status.errors['_the_form'] = field_value[0]
                    continue

                validation_status.errors[field_value[0]] = field_value[1]

            validation_status.values = getattr(exception, 'value', {})

        # Get the error handler associated to the current validation status.
        error_handler = validation_status.error_handler
        chain_validation = validation_status.chain_validation
        if error_handler is None:
            error_handler = default_im_func(controller)
            chain_validation = False

        return im_self(controller), error_handler, chain_validation