Merge pull request #345 from amcgregor/master

Addition of pre_save_validation and move of pre_save to after validation.
This commit is contained in:
Ross Lawley
2013-06-04 02:13:25 -07:00
4 changed files with 36 additions and 4 deletions

View File

@@ -195,7 +195,7 @@ class Document(BaseDocument):
the cascade save using cascade_kwargs which overwrites the
existing kwargs with custom values
"""
signals.pre_save.send(self.__class__, document=self)
signals.pre_save_validation.send(self.__class__, document=self)
if validate:
self.validate(clean=clean)
@@ -206,7 +206,9 @@ class Document(BaseDocument):
doc = self.to_mongo()
created = ('_id' not in doc or self._created or force_insert)
signals.pre_save.send(self.__class__, document=self, created=created)
try:
collection = self._get_collection()
if created:

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
__all__ = ['pre_init', 'post_init', 'pre_save', 'post_save',
'pre_delete', 'post_delete']
__all__ = ['pre_init', 'post_init', 'pre_save_validation', 'pre_save',
'post_save', 'pre_delete', 'post_delete']
signals_available = False
try:
@@ -38,6 +38,7 @@ _signals = Namespace()
pre_init = _signals.signal('pre_init')
post_init = _signals.signal('post_init')
pre_save_validation = _signals.signal('pre_save_validation')
pre_save = _signals.signal('pre_save')
post_save = _signals.signal('post_save')
pre_delete = _signals.signal('pre_delete')