Fixes to signals
The sender is the class of the document not the instance - easier to hook into
This commit is contained in:
@@ -600,7 +600,7 @@ class TopLevelDocumentMetaclass(DocumentMetaclass):
|
||||
class BaseDocument(object):
|
||||
|
||||
def __init__(self, **values):
|
||||
signals.pre_init.send(self, values=values)
|
||||
signals.pre_init.send(self.__class__, document=self, values=values)
|
||||
|
||||
self._data = {}
|
||||
# Assign default values to instance
|
||||
@@ -619,7 +619,7 @@ class BaseDocument(object):
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
signals.post_init.send(self)
|
||||
signals.post_init.send(self.__class__, document=self)
|
||||
|
||||
def _get_FIELD_display(self, field):
|
||||
"""Returns the display value for a choice field"""
|
||||
|
||||
@@ -91,7 +91,7 @@ class Document(BaseDocument):
|
||||
For example, ``save(..., w=2, fsync=True)`` will wait until at least two servers
|
||||
have recorded the write and will force an fsync on each server being written to.
|
||||
"""
|
||||
signals.pre_save.send(self)
|
||||
signals.pre_save.send(self.__class__, document=self)
|
||||
|
||||
if validate:
|
||||
self.validate()
|
||||
@@ -122,7 +122,7 @@ class Document(BaseDocument):
|
||||
id_field = self._meta['id_field']
|
||||
self[id_field] = self._fields[id_field].to_python(object_id)
|
||||
self._changed_fields = []
|
||||
signals.post_save.send(self, created=created)
|
||||
signals.post_save.send(self.__class__, document=self, created=created)
|
||||
|
||||
def delete(self, safe=False):
|
||||
"""Delete the :class:`~mongoengine.Document` from the database. This
|
||||
@@ -130,7 +130,7 @@ class Document(BaseDocument):
|
||||
|
||||
:param safe: check if the operation succeeded before returning
|
||||
"""
|
||||
signals.pre_delete.send(self)
|
||||
signals.pre_delete.send(self.__class__, document=self)
|
||||
|
||||
id_field = self._meta['id_field']
|
||||
object_id = self._fields[id_field].to_mongo(self[id_field])
|
||||
@@ -140,7 +140,7 @@ class Document(BaseDocument):
|
||||
message = u'Could not delete document (%s)' % err.message
|
||||
raise OperationError(message)
|
||||
|
||||
signals.post_delete.send(self)
|
||||
signals.post_delete.send(self.__class__, document=self)
|
||||
|
||||
def reload(self):
|
||||
"""Reloads all attributes from the database.
|
||||
|
||||
Reference in New Issue
Block a user