diff options
author | Kabir <kabir@gnowledge.org> | 2012-05-11 13:22:27 +0530 |
---|---|---|
committer | Kabir <kabir@gnowledge.org> | 2012-05-11 13:22:27 +0530 |
commit | 0ea8ff7c34af66f2c8028ea51950f9415537c4ee (patch) | |
tree | ed65210eef6d3b470ed88dcf93b73b083b582047 /gstudio/models.py | |
parent | ee3c53484190eab032c28471d2082310b04dab86 (diff) | |
download | gnowsys-0ea8ff7c34af66f2c8028ea51950f9415537c4ee.tar.gz |
Code modified to enable reversion disable feature
Diffstat (limited to 'gstudio/models.py')
-rw-r--r-- | gstudio/models.py | 334 |
1 files changed, 256 insertions, 78 deletions
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']) |