Backport transaction handling to document model events

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-11-12 13:48:31 -04:00
parent 8ee9ac239d
commit b5b3312d39
2 changed files with 31 additions and 24 deletions

View File

@@ -1,3 +1,7 @@
3.3.11 (2019-XX-XX)
===================
- Backport transaction handling to document model events.
3.2.10 (2019-11-19)
===================
- Auto-import dependencies. No need to use:

View File

@@ -110,10 +110,11 @@ class Document(models.Model):
self.deleted_date_time = now()
self.save()
else:
for version in self.versions.all():
version.delete()
with transaction.atomic():
for version in self.versions.all():
version.delete()
return super(Document, self).delete(*args, **kwargs)
return super(Document, self).delete(*args, **kwargs)
def exists(self):
"""
@@ -177,21 +178,22 @@ class Document(models.Model):
user = kwargs.pop('_user', None)
_commit_events = kwargs.pop('_commit_events', True)
new_document = not self.pk
super(Document, self).save(*args, **kwargs)
with transaction.atomic():
super(Document, self).save(*args, **kwargs)
if new_document:
if user:
self.add_as_recent_document_for_user(user)
event_document_create.commit(
actor=user, target=self, action_object=self.document_type
)
if new_document:
if user:
self.add_as_recent_document_for_user(user)
event_document_create.commit(
actor=user, target=self, action_object=self.document_type
)
else:
event_document_create.commit(
target=self, action_object=self.document_type
)
else:
event_document_create.commit(
target=self, action_object=self.document_type
)
else:
if _commit_events:
event_document_properties_edit.commit(actor=user, target=self)
if _commit_events:
event_document_properties_edit.commit(actor=user, target=self)
def save_to_file(self, *args, **kwargs):
return self.latest_version.save_to_file(*args, **kwargs)
@@ -200,15 +202,16 @@ class Document(models.Model):
has_changed = self.document_type != document_type
self.document_type = document_type
self.save()
if has_changed or force:
post_document_type_change.send(
sender=self.__class__, instance=self
)
with transaction.atomic():
self.save()
if has_changed or force:
post_document_type_change.send(
sender=self.__class__, instance=self
)
event_document_type_change.commit(actor=_user, target=self)
if _user:
self.add_as_recent_document_for_user(user=_user)
event_document_type_change.commit(actor=_user, target=self)
if _user:
self.add_as_recent_document_for_user(user=_user)
@property
def size(self):