diff options
-rw-r--r-- | demo/settings.py | 2 | ||||
-rw-r--r-- | gstudio/models.py | 334 | ||||
-rw-r--r-- | gstudio/settings.py | 2 | ||||
-rw-r--r-- | objectapp/models.py | 46 | ||||
-rw-r--r-- | objectapp/settings.py | 2 |
5 files changed, 295 insertions, 91 deletions
diff --git a/demo/settings.py b/demo/settings.py index a325258..77296fb 100644 --- a/demo/settings.py +++ b/demo/settings.py @@ -157,7 +157,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.sites', 'mptt', - 'reversion', + # 'reversion', 'tagging', 'django_xmlrpc', 'grappelli.dashboard', diff --git a/gstudio/models.py b/gstudio/models.py index 65262cc..4e047fc 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -93,6 +93,7 @@ from gstudio.settings import NODETYPE_TEMPLATES from gstudio.settings import NODETYPE_BASE_MODEL from gstudio.settings import MARKDOWN_EXTENSIONS from gstudio.settings import AUTO_CLOSE_COMMENTS_AFTER +from gstudio.settings import GSTUDIO_VERSIONING from gstudio.managers import nodetypes_published from gstudio.managers import NodetypePublishedManager from gstudio.managers import NodePublishedManager @@ -103,11 +104,13 @@ from gstudio.url_shortener import get_url_shortener from gstudio.signals import ping_directories_handler from gstudio.signals import ping_external_urls_handler import json -import reversion +if GSTUDIO_VERSIONING: + import reversion from reversion.models import Version from django.core import serializers from reversion.models import * + NODETYPE_CHOICES = ( ('ND', 'Nodes'), ( 'OB' ,'Objects'), @@ -210,6 +213,9 @@ class NID(models.Model): slug = models.SlugField(help_text=_('used for publication'), unique_for_date='creation_date', max_length=255) + nodemodel = models.CharField(_('nodemodel'),max_length=255) + + def get_serialized_dict(self): @@ -241,22 +247,25 @@ class NID(models.Model): @property def ref(self): - """ - Returns the object reference the id belongs to. - """ - try: - """ - ALGO: get object id, go to version model, return for the given id. - """ - - # Retrieving only the relevant tupleset for the versioned objects - vrs = Version.objects.filter(type=0 , object_id=self.id) - # Returned value is a list, so splice it. - vrs = vrs[0] - except: - return None + return eval(self.nodemodel).objects.get(id=self.id) - return vrs.object + # """ + # Returns the object reference the id belongs to. + # """ + # try: + # """ + # ALGO: get object id, go to version model, return for the given id. + # """ + + # # Retrieving only the relevant tupleset for the versioned objects + # # vrs = Version.objects.filter(type=0 , object_id=self.id) + # # Returned value is a list, so splice it. + # vrs = vrs[0] + # except: + # return None + + # return vrs.object + @property def reftype(self): @@ -266,9 +275,11 @@ class NID(models.Model): try: """ ALGO: simple wrapper for the __class__.__name__ so that it can be used in templates + """ - obj = self.ref - return obj.__class__.__name__ + return self.__class__.__name__ + # obj = self.ref + # return obj.__class__.__name__ except: return None @@ -317,6 +328,8 @@ class Node(NID): sites = models.ManyToManyField(Site, verbose_name=_('sites publication'), related_name='nodetypes') + nbhood = models.TextField(help_text="The neighbourhood of the model.") + published = NodePublishedManager() def __unicode__(self): return self.title @@ -324,11 +337,16 @@ class Node(NID): class Meta: abstract=False - @reversion.create_revision() + def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Node, self).save(*args, **kwargs) # Call the "real" save() method. super(Node, self).save(*args, **kwargs) # Call the "real" save() method. + + class Edge(NID): @@ -337,9 +355,11 @@ class Edge(NID): class Meta: abstract=False - @reversion.create_revision() - # Save for edge def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Edge, self).save(*args, **kwargs) # Call the "real" save() method. + super(Edge, self).save(*args, **kwargs) # Call the "real" save() method. @@ -524,8 +544,12 @@ class Metatype(Node): verbose_name_plural = _('metatypes') # Save for metatype - @reversion.create_revision() + def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. + super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1159,8 +1183,10 @@ class Nodetype(Node): ('can_change_author', 'Can change author'), ) # Save for nodetype - @reversion.create_revision() def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Nodetype, self).save(*args, **kwargs) # Call the "real" save() method. super(Nodetype, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1343,8 +1369,13 @@ class Objecttype(Nodetype): ('can_change_author', 'Can change author'), ) # Save for Objecttype - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. + super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1390,8 +1421,14 @@ class Relationtype(Nodetype): ('can_change_author', 'Can change author'), ) # Save for Relationtype - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + self.nodemodel = self.__class__.__name__ + + super(Relationtype, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1439,8 +1476,13 @@ class Attributetype(Nodetype): ('can_change_author', 'Can change author'), ) # Save for Attributetype - @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method. super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1537,8 +1579,12 @@ class Relation(Edge): # Save for Relation - @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Relation, self).save(*args, **kwargs) # Call the "real" save() method. super(Relation, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1619,8 +1665,13 @@ class Attribute(Edge): return each.get_members # Save for Attribute - @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Attribute, self).save(*args, **kwargs) # Call the "real" save() method. + super(Attribute, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1634,8 +1685,13 @@ class AttributeCharField(Attribute): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeCharField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeCharField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1646,8 +1702,12 @@ class AttributeTextField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeTextField, self).save(*args, **kwargs) # Call the "real" save() method. super(AttributeTextField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1657,10 +1717,15 @@ class AttributeIntegerField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): - super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. + class AttributeCommaSeparatedIntegerField(Attribute): @@ -1670,8 +1735,12 @@ class AttributeCommaSeparatedIntegerField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeCommaSeparatedIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. super(AttributeCommaSeparatedIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. class AttributeBigIntegerField(Attribute): @@ -1688,8 +1757,12 @@ class AttributePositiveIntegerField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributePositiveIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. super(AttributePositiveIntegerField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1700,6 +1773,12 @@ class AttributeDecimalField(Attribute): def __unicode__(self): return self.title def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeDecimalField, self).save(*args, **kwargs) # Call the "real" save() method. + + super(AttributeDecimalField, self).save(*args, **kwargs) # Call the "real" save() method. class AttributeFloatField(Attribute): @@ -1709,8 +1788,13 @@ class AttributeFloatField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeFloatField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeFloatField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1721,6 +1805,11 @@ class AttributeBooleanField(Attribute): def __unicode__(self): return self.title def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1731,8 +1820,12 @@ class AttributeNullBooleanField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeNullBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. super(AttributeNullBooleanField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1743,8 +1836,12 @@ class AttributeDateField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeDateField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeDateField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1755,8 +1852,13 @@ class AttributeDateTimeField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeDateTimeField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeDateTimeField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1767,8 +1869,13 @@ class AttributeTimeField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeTimeField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeTimeField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1779,8 +1886,12 @@ class AttributeEmailField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeEmailField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeEmailField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1791,8 +1902,13 @@ class AttributeFileField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeFileField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeFileField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1803,8 +1919,13 @@ class AttributeFilePathField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeFilePathField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeFilePathField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1815,8 +1936,9 @@ class AttributeImageField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ super(AttributeImageField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1827,8 +1949,13 @@ class AttributeURLField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeURLField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeURLField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1839,8 +1966,13 @@ class AttributeIPAddressField(Attribute): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeIPAddressField, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeIPAddressField, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1867,8 +1999,13 @@ class Processtype(Nodetype): verbose_name_plural = _('process types') permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Processtype, self).save(*args, **kwargs) # Call the "real" save() method. + super(Processtype, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1903,8 +2040,13 @@ class Systemtype(Nodetype): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Systemtype, self).save(*args, **kwargs) # Call the "real" save() method. + super(Systemtype, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1932,6 +2074,7 @@ class AttributeSpecification(Node): def __unicode__(self): + self.nodemodel = self.__class__.__name__ return self.composed_subject @@ -1940,8 +2083,13 @@ class AttributeSpecification(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(AttributeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + super(AttributeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. @@ -1975,8 +2123,13 @@ class RelationSpecification(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(RelationSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + super(RelationSpecification, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2011,8 +2164,13 @@ class NodeSpecification(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(NodeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. + super(NodeSpecification, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2044,8 +2202,13 @@ class Expression(Node): permissions = (('can_view_all', 'Can view all'), ('can_change_author', 'Can change author'), ) - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Expression, self).save(*args, **kwargs) # Call the "real" save() method. + super(Expression, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2060,8 +2223,13 @@ class Union(Node): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Union, self).save(*args, **kwargs) # Call the "real" save() method. + super(Union, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2076,8 +2244,13 @@ class Complement(Node): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Complement, self).save(*args, **kwargs) # Call the "real" save() method. + super(Complement, self).save(*args, **kwargs) # Call the "real" save() method. @@ -2090,48 +2263,53 @@ class Intersection(Node): def __unicode__(self): return self.title - @reversion.create_revision() + # @reversion.create_revision() def save(self, *args, **kwargs): + self.nodemodel = self.__class__.__name__ + if GSTUDIO_VERSIONING: + with reversion.create_revision(): + super(Intersection, self).save(*args, **kwargs) # Call the "real" save() method. + super(Intersection, self).save(*args, **kwargs) # Call the "real" save() method. +if GSTUDIO_VERSIONING == True: + reversion.register(NID) -reversion.register(NID) - -if not reversion.is_registered(Systemtype): - reversion.register(Systemtype) + if not reversion.is_registered(Systemtype): + reversion.register(Systemtype) -if not reversion.is_registered(Objecttype): - reversion.register(Objecttype , follow=["nodetype_ptr"]) + if not reversion.is_registered(Objecttype): + reversion.register(Objecttype , follow=["nodetype_ptr"]) -if not reversion.is_registered(Node): - reversion.register(Node , follow=["nid_ptr"]) + if not reversion.is_registered(Node): + reversion.register(Node , follow=["nid_ptr"]) -if not reversion.is_registered(Edge): - reversion.register(Edge , follow=["nid_ptr"]) + if not reversion.is_registered(Edge): + reversion.register(Edge , follow=["nid_ptr"]) -if not reversion.is_registered(Processtype): - reversion.register(Processtype, follow=["changing_attributetype_set", "changing_relationtype_set"]) + if not reversion.is_registered(Processtype): + reversion.register(Processtype, follow=["changing_attributetype_set", "changing_relationtype_set"]) -if not reversion.is_registered(Nodetype): - reversion.register(Nodetype, follow=["node_ptr","parent", "metatypes","prior_nodes", "posterior_nodes"]) + if not reversion.is_registered(Nodetype): + reversion.register(Nodetype, follow=["node_ptr","parent", "metatypes","prior_nodes", "posterior_nodes"]) -if not reversion.is_registered(Metatype): - reversion.register(Metatype, follow=["node_ptr","parent"]) + if not reversion.is_registered(Metatype): + reversion.register(Metatype, follow=["node_ptr","parent"]) -if not reversion.is_registered(Relationtype): - reversion.register(Relationtype, follow=["left_subjecttype", "right_subjecttype"]) + if not reversion.is_registered(Relationtype): + reversion.register(Relationtype, follow=["left_subjecttype", "right_subjecttype"]) -if not reversion.is_registered(Attributetype): - reversion.register(Attributetype, follow=["subjecttype"]) + if not reversion.is_registered(Attributetype): + reversion.register(Attributetype, follow=["subjecttype"]) -if not reversion.is_registered(Attribute): - reversion.register(Attribute, follow=["subject", "attributetype"]) + if not reversion.is_registered(Attribute): + reversion.register(Attribute, follow=["subject", "attributetype"]) -if not reversion.is_registered(Relation): - reversion.register(Relation, follow=["left_subject", "right_subject", "relationtype"]) + if not reversion.is_registered(Relation): + reversion.register(Relation, follow=["left_subject", "right_subject", "relationtype"]) moderator.register(Nodetype, NodetypeCommentModerator) mptt.register(Metatype, order_insertion_by=['title']) diff --git a/gstudio/settings.py b/gstudio/settings.py index dceb80f..7560667 100644 --- a/gstudio/settings.py +++ b/gstudio/settings.py @@ -152,3 +152,5 @@ TWITTER_ACCESS_SECRET = getattr(settings, 'TWITTER_ACCESS_SECRET', '') USE_TWITTER = getattr(settings, 'GSTUDIO_USE_TWITTER', bool(TWITTER_ACCESS_KEY and TWITTER_ACCESS_SECRET and \ TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRET)) + +GSTUDIO_VERSIONING = False diff --git a/objectapp/models.py b/objectapp/models.py index a27832a..182b0f2 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""" @@ -655,9 +658,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: @@ -699,8 +711,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: @@ -739,8 +756,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. @@ -748,15 +770,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) diff --git a/objectapp/settings.py b/objectapp/settings.py index 885a870..727b716 100644 --- a/objectapp/settings.py +++ b/objectapp/settings.py @@ -133,3 +133,5 @@ TWITTER_ACCESS_SECRET = getattr(settings, 'TWITTER_ACCESS_SECRET', '') USE_TWITTER = getattr(settings, 'OBJECTAPP_USE_TWITTER', bool(TWITTER_ACCESS_KEY and TWITTER_ACCESS_SECRET and \ TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRET)) + +OBJECTAPP_VERSIONING = False |