[Zope3-dev] Formlib error handling

dev at projekt01.ch dev at projekt01.ch
Sat Apr 22 11:31:39 EDT 2006


The formlib.EditForm dosen't catch all errors form widgets.

The following method catches only InputError:

def getWidgetsData(widgets, form_prefix, data):
    errors = []
    form_prefix += '.'

    for input, widget in widgets.__iter_input_and_widget__():
        if input and IInputWidget.providedBy(widget):
            name = _widgetKey(widget, form_prefix)

            if not widget.hasInput():
                raise interfaces.FormError("No input", name)

            try:
                data[name] = widget.getInputValue()
            except InputErrors, error:
                errors.append(error)

    return errors

How can I enhance the error handling for 
WrongContainedType or NotUnique which are ValueErrors?

Do I miss something or is it correct to improve the 
validation in this method. Or is there in general a mess
in the widget implementation and it's error handling.

Hm, is it correct how the sequence widget handles errors
in the getInputValue method?

e.g.
    def getInputValue(self):
        """Return converted and validated widget data.

        If there is no user input and the field is required, then a
        ``MissingInputError`` will be raised.

        If there is no user input and the field is not required, then
        the field default value will be returned.

        A ``WidgetInputError`` is raised in the case of one or more
        errors encountered, inputting, converting, or validating the data.
        """
        if self.hasInput():
            self.preserve_widgets = True
            sequence = self._type(self._generateSequence())
            if sequence != self.context.missing_value:
                self.context.validate(sequence)
            elif self.context.required:
                raise MissingInputError(self.context.__name__,
                                        self.context.title)
            return sequence
        raise MissingInputError(self.context.__name__, self.context.title)


and dosen't convert errors raised in 
*self.context.validate(sequence)* to a ValidationError (InputErrors) ?

Regards
Roger Ineichen
_____________________________
Projekt01 GmbH
www.projekt01.ch
Boesch 65
6331 Hünenberg
phone     +41 (0)41 781 01 78
mobile    +41 (0)79 340 52 32
fax       +41 (0)41 781 00 78
email roger.ineichen at projekt01.ch
_____________________________
END OF MESSAGE



More information about the Zope3-dev mailing list