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 f4715a5..c28b81c 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. @@ -1179,8 +1203,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. @@ -1363,8 +1389,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. @@ -1410,8 +1441,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. @@ -1459,8 +1496,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. @@ -1557,8 +1599,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. @@ -1639,8 +1685,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. @@ -1654,8 +1705,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. @@ -1666,8 +1722,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. @@ -1677,10 +1737,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): @@ -1690,8 +1755,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): @@ -1708,8 +1777,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. @@ -1720,6 +1793,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): @@ -1729,8 +1808,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. @@ -1741,6 +1825,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. @@ -1751,8 +1840,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. @@ -1763,8 +1856,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. @@ -1775,8 +1872,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. @@ -1787,8 +1889,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. @@ -1799,8 +1906,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. @@ -1811,8 +1922,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. @@ -1823,8 +1939,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. @@ -1835,8 +1956,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. @@ -1847,8 +1969,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. @@ -1859,8 +1986,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. @@ -1887,8 +2019,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. @@ -1923,8 +2060,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. @@ -1952,6 +2094,7 @@ class AttributeSpecification(Node): def __unicode__(self): + self.nodemodel = self.__class__.__name__ return self.composed_subject @@ -1960,8 +2103,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. @@ -1995,8 +2143,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. @@ -2031,8 +2184,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. @@ -2064,8 +2222,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. @@ -2080,8 +2243,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. @@ -2096,8 +2264,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. @@ -2110,48 +2283,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 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) diff --git a/objectapp/settings.py b/objectapp/settings.py index 2b215f0..ba6004d 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 |