Пример #1
0
    def extractData(self, fields):
        data = FieldsValues(self, fields)
        errors = Errors()

        for field in fields:
            if not field.available(self):
                continue

            # Widget extraction and validation
            extractor = getWidgetExtractor(field, self, self.request)
            if extractor is not None:
                value, error = extractor.extract()
                if error is None:
                    error = field.validate(value, self.context)
                if error is not None:
                    if not interfaces.IError.providedBy(error):
                        if interfaces.IErrors.providedBy(error):
                            # this is an Errors, not implementing IError
                            # "Make it so, number one !"
                            error = Errors(
                                *error, identifier=extractor.identifier)
                        else:
                            error = Error(
                                error, identifier=extractor.identifier)
                    errors.append(error)
                data[field.identifier] = value

        # Generic form validation
        validation_errors = self.validateData(fields, data)
        errors.extend(validation_errors)
        self.errors = errors
        return (data, errors)
Пример #2
0
    def extractData(self, fields):
        # XXX to review this
        cached = self._extracted.get(fields)
        if cached is not None:
            return cached
        data = FieldsValues(self, fields)
        errors = Errors()
        self._extracted[fields] = (data, errors)

        for field in fields:
            if not field.available(self):
                continue

            # Widget extraction and validation
            extractor = self.widgetFactory.extractor(field)
            if extractor is not None:
                value, error = extractor.extract()
                if error is None:
                    error = field.validate(value, self)
                if error is not None:
                    if not IError.providedBy(error):
                        error = Error(error, extractor.identifier)
                    errors.append(error)
                data[field.identifier] = value

        # Generic form validation
        errors.extend(self.validateData(fields, data))
        if len(errors):
            # Add a form level error if not already present
            if self.prefix not in errors:
                errors.append(
                    Error(_(u"There were errors.", default=u"There were errors."),
                          self.prefix))
        self.errors = errors
        return (data, errors)
Пример #3
0
 def validateData(self, fields, data):
     errors = Errors()
     for factory in self.dataValidators:
         validator = factory(fields, self)
         for error in validator.validate(data):
             errors.append(Error(error.args[0], self.prefix))
     return errors
Пример #4
0
 def validateData(self, fields, data):
     errors = Errors()
     for factory in self.dataValidators:
         validator = factory(fields, self)
         for error in validator.validate(data):
             if not IError.providedBy(error):
                 error = Error(error, self.prefix)
             errors.append(error)
     return errors