From 5eaa9a2feb2f5109f114ce92e2243126a2c12c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sun, 29 Apr 2018 16:34:05 +0000 Subject: [PATCH] Fix #116: Remove default SOA in Extension & Force reversion context - The default for extension SOA is now None, else a new SOA named `SOA to edit` was created when adding a new extension (because of the get_or_create() ) - The mixins are now inside a reversion context else sometimes the reversion context was not set and re2o would crash on the set_comment --- machines/models.py | 3 +-- re2o/mixins.py | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/machines/models.py b/machines/models.py index 9ed973f2..6c811467 100644 --- a/machines/models.py +++ b/machines/models.py @@ -541,8 +541,7 @@ class Extension(RevMixin, AclMixin, models.Model): ) soa = models.ForeignKey( 'SOA', - on_delete=models.CASCADE, - default=SOA.new_default_soa + on_delete=models.CASCADE ) class Meta: diff --git a/re2o/mixins.py b/re2o/mixins.py index c13e841c..2ee049cc 100644 --- a/re2o/mixins.py +++ b/re2o/mixins.py @@ -24,6 +24,7 @@ A set of mixins used all over the project to avoid duplicating code """ from reversion import revisions as reversion +from django.db import transaction class RevMixin(object): @@ -33,13 +34,16 @@ class RevMixin(object): def save(self, *args, **kwargs): """ Creates a version of this object and save it to database """ if self.pk is None: - reversion.set_comment("Création") + with transaction.atomic(), reversion.create_revision(): + reversion.set_comment("Création") + return super(RevMixin, self).save(*args, **kwargs) return super(RevMixin, self).save(*args, **kwargs) def delete(self, *args, **kwargs): """ Creates a version of this object and delete it from database """ - reversion.set_comment("Suppresion") - return super(RevMixin, self).delete(*args, **kwargs) + with transaction.atomic(), reversion.create_revision(): + reversion.set_comment("Suppresion") + return super(RevMixin, self).delete(*args, **kwargs) class FormRevMixin(object):