def validate(self): """ Validate attributes and `global_validator`. If validation fails, the validator should raise `ValidationError`. """ if self.readonly: raise ValidationError('Cannot validate a read-only FieldSet') if self.data is None: raise ValidationError('Cannot validate without binding data') success = True for field in self.render_fields.values(): success = field._validate() and success # run this _after_ the field validators, since each field validator # resets its error list. we want to allow the global validator to add # errors to individual fields. if self.validator: self._errors = [] try: self.validator(self) except ValidationError as e: self._errors.append(e.message) success = False return success
def passwords_match(value, field): value1 = field.renderer.params.getone(field.renderer.name) value2 = field.renderer.params.getone(field.renderer.name + '_confirm') if value1 != value2: raise ValidationError(_("Passwords do not match"))
def unique_validator(value, f): query = f.query(f.model.__class__) query = query.filter_by(**{f.name: f.value}) if f.parent._bound_pk is None and query.first(): raise ValidationError(_(u'Duplicate record'))