diff options
Diffstat (limited to 'objectapp/models.py')
-rw-r--r-- | objectapp/models.py | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/objectapp/models.py b/objectapp/models.py index 2c56dbf..4ed7279 100644 --- a/objectapp/models.py +++ b/objectapp/models.py @@ -98,7 +98,6 @@ from gstudio.models import Node from gstudio.models import Edge from gstudio.models import Author -import reversion from objectapp.settings import UPLOAD_TO from objectapp.settings import MARKUP_LANGUAGE from objectapp.settings import GBOBJECT_TEMPLATES @@ -113,12 +112,16 @@ from objectapp.moderator import GbobjectCommentModerator from objectapp.url_shortener import get_url_shortener from objectapp.signals import ping_directories_handler from objectapp.signals import ping_external_urls_handler -from reversion.models import * +from objectapp.settings import OBJECTAPP_VERSIONING +if OBJECTAPP_VERSIONING: + import reversion + from reversion.models import * counter = 1 attr_counter = -1 + ''' class Author(User): """Proxy Model around User""" @@ -671,9 +674,18 @@ class Gbobject(Node): 'day': self.creation_date.strftime('%d'), 'slug': self.slug}) - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if OBJECTAPP_VERSIONING: + with reversion.create_revision(): + super(Gbobject, self).save(*args, **kwargs) # Call the "real" save() method. + super(Gbobject, self).save(*args, **kwargs) # Call the "real" save() method. + @property + def ref(self): + return eval(self.nodemodel).objects.get(id=self.id) + class Meta: @@ -715,8 +727,13 @@ class Process(Gbobject): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if OBJECTAPP_VERSIONING: + with reversion.create_revision(): + super(Process, self).save(*args, **kwargs) # Call the "real" save() method. + super(Process, self).save(*args, **kwargs) # Call the "real" save() method. class Meta: @@ -755,8 +772,13 @@ class System(Gbobject): system_set = models.ManyToManyField('self', related_name="in_system_set_of", verbose_name='nested systems', blank=True, null=False) - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if OBJECTAPP_VERSIONING: + with reversion.create_revision(): + super(System, self).save(*args, **kwargs) # Call the "real" save() method. + super(System, self).save(*args, **kwargs) # Call the "real" save() method. @@ -764,15 +786,15 @@ class System(Gbobject): return self.title - -if not reversion.is_registered(Process): - reversion.register(Process, follow=["priorstate_attribute_set", "priorstate_relation_set", "poststate_attribute_set", "poststate_relation_set", "prior_nodes", "posterior_nodes"]) +if OBJECTAPP_VERSIONING == True: + if not reversion.is_registered(Process): + reversion.register(Process, follow=["priorstate_attribute_set", "priorstate_relation_set", "poststate_attribute_set", "poststate_relation_set", "prior_nodes", "posterior_nodes"]) -if not reversion.is_registered(System): - reversion.register(System, follow=["systemtypes", "gbobject_set", "relation_set", "attribute_set", "process_set", "system_set", "prior_nodes", "posterior_nodes"]) + if not reversion.is_registered(System): + reversion.register(System, follow=["systemtypes", "gbobject_set", "relation_set", "attribute_set", "process_set", "system_set", "prior_nodes", "posterior_nodes"]) -if not reversion.is_registered(Gbobject): - reversion.register(Gbobject, follow=["objecttypes", "prior_nodes", "posterior_nodes"]) + if not reversion.is_registered(Gbobject): + reversion.register(Gbobject, follow=["objecttypes", "prior_nodes", "posterior_nodes"]) moderator.register(Gbobject, GbobjectCommentModerator) |