Add transaction handling to document model events
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -133,6 +133,7 @@
|
||||
of index tree templates.
|
||||
- Add document trashed event. Closes GitLab issue #608
|
||||
Thanks to Vikas Kedia (@vikaskedia) for the report.
|
||||
- Add transaction handling to document model events.
|
||||
|
||||
3.2.10 (2019-XX-XX)
|
||||
===================
|
||||
|
||||
@@ -121,10 +121,11 @@ class Document(models.Model):
|
||||
self.save(_commit_events=False)
|
||||
event_document_trashed.commit(actor=_user, target=self)
|
||||
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):
|
||||
"""
|
||||
@@ -224,21 +225,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)
|
||||
@@ -247,15 +249,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):
|
||||
|
||||
Reference in New Issue
Block a user