Make validation-lists possible. Example:

class Doc(Document):
        country = StringField(validation=['DE', 'AT', 'CH'])
This commit is contained in:
Florian Schlachter 2010-04-16 18:00:51 +02:00
parent 48facec524
commit f3ca9fa4c5

View File

@ -78,8 +78,11 @@ class BaseField(object):
def validate(self, value):
"""Perform validation on a value.
"""
if self.validation is not None and not self.validation(value):
raise ValidationError('Value does not match custom validation method.')
if self.validation is not None:
if isinstance(self.validation, list):
raise ValidationError('Value not in validation list.')
elif callable(self.validation) and not self.validation(value):
raise ValidationError('Value does not match custom validation method.')
class ObjectIdField(BaseField):
"""An field wrapper around MongoDB's ObjectIds.