def delete(self, hard=False, using=None, *args, **kwargs): # removed from the database or move to trash if self.version_in_trash or hard: # without sending signals post_delete, pre_delete self._delete(using=None, *args, **kwargs) elif hard: # with sending signals signal_allow(self, models.signals.pre_delete) signal_allow(self, models.signals.post_delete) self._delete(using=None, *args, **kwargs) signal_allow(self, models.signals.pre_delete, count=0) signal_allow(self, models.signals.post_delete, count=0) else: # with sending "virtual" signals using = using or router.db_for_write(self.__class__, instance=self) assert self._get_pk_val() is not None, \ "%s object can't be deleted because its %s attribute is set to None." % \ (self._meta.object_name, self._meta.pk.attname) collector = Collector(using=using) collector.collect([self]) # send pre_delete signals for model, obj in collector.instances_with_model(): if not model._meta.auto_created: models.signals.pre_delete.send(sender=model, instance=obj, using=using) self.version_in_trash = True self.version_date = _get_current_date() self._save() # send post_delete signals for model, obj in collector.instances_with_model(): if not model._meta.auto_created: models.signals.post_delete.send(sender=model, instance=obj, using=using)
def delete(self, hard=False, using=None, *args, **kwargs): # removed from the database or move to trash if self.version_in_trash or hard: # without sending signals post_delete, pre_delete self._delete(using=None, *args, **kwargs) elif hard: # with sending signals signal_allow(self, models.signals.pre_delete) signal_allow(self, models.signals.post_delete) self._delete(using=None, *args, **kwargs) signal_allow(self, models.signals.pre_delete, count=0) signal_allow(self, models.signals.post_delete, count=0) else: # with sending "virtual" signals using = using or router.db_for_write(self.__class__, instance=self) assert self._get_pk_val() is not None, \ "%s object can't be deleted because its %s attribute is set to None." % \ (self._meta.object_name, self._meta.pk.attname) collector = Collector(using=using) collector.collect([self]) # send pre_delete signals for model, obj in collector.instances_with_model(): if not model._meta.auto_created: models.signals.pre_delete.send( sender=model, instance=obj, using=using ) self.version_in_trash = True self.version_date = _get_current_date() self._save() # send post_delete signals for model, obj in collector.instances_with_model(): if not model._meta.auto_created: models.signals.post_delete.send( sender=model, instance=obj, using=using )
def save(self, force_insert=False, force_update=False, using=None): # If no changes, then we drop writing. if self.version_parent_rev_pk: if self.get_version_hash() == self.version_parent_rev_pk.\ version_hash: return # Permission to send a signal. signal_allow(self, models.signals.pre_save) signal_allow(self, models.signals.post_save) self._save(force_insert, force_update, using) # Withdrawal of permission to send a signal. signal_allow(self, models.signals.pre_save, count=0) signal_allow(self, models.signals.post_save, count=0) new_revision = self.create_revision() new_revision.commit() new_revision.set_as_main_version()