Got EmbeddedDocumentFields working
Added validation on EmbeddedDocumentField, added tests for EmbeddedDocumentFields.
This commit is contained in:
parent
48418d5a60
commit
5a87534c22
5 changed files with 46 additions and 5 deletions
|
|
@ -4,7 +4,8 @@ from document import EmbeddedDocument
|
|||
import re
|
||||
|
||||
|
||||
__all__ = ['StringField', 'IntField', 'ValidationError']
|
||||
__all__ = ['StringField', 'IntField', 'EmbeddedDocumentField',
|
||||
'ValidationError']
|
||||
|
||||
|
||||
class StringField(BaseField):
|
||||
|
|
@ -52,7 +53,15 @@ class EmbeddedDocumentField(BaseField):
|
|||
|
||||
def __init__(self, document, **kwargs):
|
||||
if not issubclass(document, EmbeddedDocument):
|
||||
raise ValidationError('Invalid embedded document provided to an '
|
||||
'EmbeddedDocumentField')
|
||||
raise ValidationError('Invalid embedded document class provided '
|
||||
'to an EmbeddedDocumentField')
|
||||
self.document = document
|
||||
super(EmbeddedDocumentField, self).__init__(**kwargs)
|
||||
|
||||
def _to_python(self, value):
|
||||
return value
|
||||
|
||||
def _validate(self, value):
|
||||
if not isinstance(value, self.document):
|
||||
raise ValidationError('Invalid embedded document instance '
|
||||
'provided to an EmbeddedDocumentField')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue