def clean(self): self.vat = self.vat.strip() self.city = self.city.strip() validators.all_valid({ 'vat': (validators.validate_vat, self.vat, self.country), 'zipcode': (validators.validate_zipcode, self.zipcode, self.country) })
def clean(self): self.description = self.description.strip() if hasattr(self, 'content_type'): validators.all_valid({ 'content_type': (self.handler.validate_content_type, self), 'match': (self.handler.validate_match, self), 'metric': (self.handler.validate_metric, self), 'order_description': (self.handler.validate_order_description, self), })
def validate_value(self, value): if value: validators.all_valid(value, self.validators) valid_types = list(self.types) if isinstance(self.default, (list, tuple)): valid_types.extend([list, tuple]) valid_types.append(type(self.default)) if not isinstance(value, tuple(valid_types)): raise ValidationError( "%s is not a valid type (%s)." % (type(value).__name__, ", ".join(t.__name__ for t in valid_types)) )
def validate_value(self, value): if value: validators.all_valid(value, self.validators) valid_types = list(self.types) if self.choices: choices = self.choices if callable(choices): choices = choices() choices = [n for n,v in choices] values = value if not isinstance(values, (list, tuple)): values = [value] for cvalue in values: if cvalue not in choices: raise ValidationError("'%s' not in '%s'" % (value, ', '.join(choices))) if isinstance(self.default, (list, tuple)): valid_types.extend([list, tuple]) valid_types.append(type(self.default)) if not isinstance(value, tuple(valid_types)): raise ValidationError("%s is not a valid type (%s)." % (type(value).__name__, ', '.join(t.__name__ for t in valid_types)) )
def validate_value(self, value): if value: validators.all_valid(value, self.validators) valid_types = list(self.types) if self.choices: choices = self.choices if callable(choices): choices = choices() choices = [n for n, v in choices] values = value if not isinstance(values, (list, tuple)): values = [value] for cvalue in values: if cvalue not in choices: raise ValidationError("'%s' not in '%s'" % (value, ', '.join(choices))) if isinstance(self.default, (list, tuple)): valid_types.extend([list, tuple]) valid_types.append(type(self.default)) if not isinstance(value, tuple(valid_types)): raise ValidationError( "%s is not a valid type (%s)." % (type(value).__name__, ', '.join(t.__name__ for t in valid_types)))