8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

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
This commit is contained in:
Maël Kervella 2018-04-29 16:34:05 +00:00
parent 52a35e523d
commit 5eaa9a2feb
2 changed files with 8 additions and 5 deletions

View file

@ -541,8 +541,7 @@ class Extension(RevMixin, AclMixin, models.Model):
) )
soa = models.ForeignKey( soa = models.ForeignKey(
'SOA', 'SOA',
on_delete=models.CASCADE, on_delete=models.CASCADE
default=SOA.new_default_soa
) )
class Meta: class Meta:

View file

@ -24,6 +24,7 @@ A set of mixins used all over the project to avoid duplicating code
""" """
from reversion import revisions as reversion from reversion import revisions as reversion
from django.db import transaction
class RevMixin(object): class RevMixin(object):
@ -33,11 +34,14 @@ class RevMixin(object):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
""" Creates a version of this object and save it to database """ """ Creates a version of this object and save it to database """
if self.pk is None: if self.pk is None:
with transaction.atomic(), reversion.create_revision():
reversion.set_comment("Création") reversion.set_comment("Création")
return super(RevMixin, self).save(*args, **kwargs) return super(RevMixin, self).save(*args, **kwargs)
return super(RevMixin, self).save(*args, **kwargs)
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):
""" Creates a version of this object and delete it from database """ """ Creates a version of this object and delete it from database """
with transaction.atomic(), reversion.create_revision():
reversion.set_comment("Suppresion") reversion.set_comment("Suppresion")
return super(RevMixin, self).delete(*args, **kwargs) return super(RevMixin, self).delete(*args, **kwargs)