summaryrefslogtreecommitdiff
path: root/gstudio/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'gstudio/models.py')
-rw-r--r--gstudio/models.py1071
1 files changed, 848 insertions, 223 deletions
diff --git a/gstudio/models.py b/gstudio/models.py
index 5b5cf424..995ecaf9 100644
--- a/gstudio/models.py
+++ b/gstudio/models.py
@@ -65,7 +65,9 @@
+
"""Super models of Gstudio """
+
import warnings
from datetime import datetime
from django.db import models
@@ -110,6 +112,8 @@ if GSTUDIO_VERSIONING:
from reversion.models import Version
from django.core import serializers
from reversion.models import *
+from reversion.helpers import *
+import ast
NODETYPE_CHOICES = (
@@ -216,35 +220,71 @@ class NID(models.Model):
max_length=255)
nodemodel = models.CharField(_('nodemodel'),max_length=255)
+ @property
+ def get_revisioncount(self):
+ """
+ Returns Number of Version
+ """
+ i=0
+ ver=Version.objects.get_for_object(self)
+ for each in ver:
+ i=i+1
+ return i
+ @property
+ def get_version_list(self):
+ """
+ Returns Version list
+ """
+ ver=Version.objects.get_for_object(self)
+ return ver
-
+ @property
+ def get_ssid(self):
+ """
+ return snapshot ids (revision id).
+ returns a list.
+ """
+ slist=[]
+ vlist=self.get_version_list
+ for each in vlist:
+ slist.append(each.id)
+ return slist
+
+ def version_info(self,ssid):
+ version_object=Version.objects.get(id=ssid)
+ return version_object.field_dict
+
+
+ def get_version_nbh(self,ssid):
+ """
+ Returns Version nbh
+ """
+ ver_dict=self.version_info(ssid)
+ ver_nbh_list=[]
+ ver_nbh_dict={}
+ for item in self.get_nbh.keys():
+ if item in ver_dict.keys():
+ ver_nbh_list.append(item)
+ for each in ver_nbh_list:
+ ver_nbh_dict[each]=ver_dict[each]
+ return ver_nbh_dict
+
def get_serialized_dict(self):
"""
return the fields in a serialized form of the current object using the __dict__ function.
"""
return self.__dict__
- @property
- def get_app_name(self):
- if self.ref.__class__.__name__=='Gbobject' or self.ref.__class__.__name__=='Process' or self.ref.__class__.__name__=='System' :
- return 'type'
-
@models.permalink
def get_absolute_url(self):
"""Return nodetype's URL"""
- if self.get_app_name=='type':
- return ('objectapp_gbobject_detail', (), {
- 'year': self.creation_date.strftime('%Y'),
- 'month': self.creation_date.strftime('%m'),
- 'day': self.creation_date.strftime('%d'),
- 'slug': self.slug})
- else:
- return ('gstudio_nodetype_detail', (), {
- 'year': self.creation_date.strftime('%Y'),
- 'month': self.creation_date.strftime('%m'),
- 'day': self.creation_date.strftime('%d'),
- 'slug': self.slug})
+
+ return ('gstudio_nodetype_detail', (), {
+ 'year': self.creation_date.strftime('%Y'),
+ 'month': self.creation_date.strftime('%m'),
+ 'day': self.creation_date.strftime('%d'),
+ 'slug': self.slug})
@property
def ref(self):
@@ -264,8 +304,7 @@ class NID(models.Model):
# # Returned value is a list, so splice it.
# vrs = vrs[0]
# except:
- # return None
-
+ # return None
# return vrs.object
@@ -288,36 +327,61 @@ class NID(models.Model):
@property
def getat(self):
+
"""This is will give the possible attributetypes """
try:
+ pt = []
attributetype = []
- ot = self.ref
- attributetype.append(ot.subjecttype_of.all())
+ returndict = {}
+
+ pt.append(self.ref)
+ obj = self.ref
+ while obj.parent:
+ pt.append((obj.parent).ref)
+ obj=obj.parent
+
+ for each in pt:
+ attributetype.append(each.subjecttype_of.all())
+
attributetype = [num for elem in attributetype for num in elem]
- return attributetype
+
+ for i in attributetype:
+ if str(i.applicable_nodetypes) == 'OT':
+ returndict.update({str(i.title):i.id})
+
+ return returndict.keys()
except:
return None
@property
def getrt(self):
- pt =[] #contains parenttype
- reltype =[] #contains relationtype
- titledict = {} #contains relationtype's title
- inverselist = [] #contains relationtype's inverse
- finaldict = {} #contains either title of relationtype or inverse of relationtype
- listval=[] #contains keys of titledict to check whether parenttype id is equals to listval's left or right subjecttypeid
- # pt.append(Objecttype.objects.get(title = str(gbid)))
- # name = NID.objects.get(title = str(gbid))
+ """pt =[] contains parenttype
+ reltype =[] contains relationtype
+ titledict = {} contains relationtype's title
+ inverselist = [] contains relationtype's inverse
+ finaldict = {} contains either title of relationtype or inverse of relationtype
+ listval=[] contains keys of titledict to check whether parenttype id is equals to listval's left or right subjecttypeid"""
+
+ pt =[]
+ reltype =[]
+ titledict = {}
+ inverselist = []
+ finaldict = {}
+ listval=[]
+
pt.append(self.ref)
+ obj = self.ref
+ while obj.parent:
+ pt.append((obj.parent).ref)
+ obj=obj.parent
+
for i in range(len(pt)):
if Relationtype.objects.filter(left_subjecttype = pt[i].id):
reltype.append(Relationtype.objects.filter(left_subjecttype = pt[i].id))
if Relationtype.objects.filter(right_subjecttype = pt[i].id):
reltype.append(Relationtype.objects.filter(right_subjecttype = pt[i].id))
-
- # it converts 2 or more list as one list
reltype = [num for elem in reltype for num in elem] #this rqud for filtering
-
+
for i in reltype:
titledict.update({i:i.id})
@@ -325,16 +389,16 @@ class NID(models.Model):
for i in range(len(titledict)):
listval.append(Relationtype.objects.get(title = titledict.keys()[i]))
inverselist.append(str(titledict.keys()[i].inverse))
-
-
+
for j in range(len(pt)):
for i in range(len(listval)):
- if pt[j].id == listval[i].left_subjecttype_id :
- finaldict.update({titledict.values()[i]:titledict.keys()[i]})
- elif pt[j].id == listval[i].right_subjecttype_id:
- finaldict.update({titledict.values()[i]:inverselist[i]})
+ if pt[j].id == listval[i].left_subjecttype_id and str(listval[i].left_applicable_nodetypes) == 'OT' :
+ finaldict.update({titledict.keys()[i]:titledict.values()[i]})
+ if pt[j].id == listval[i].right_subjecttype_id and str(listval[i].right_applicable_nodetypes)=='OT':
+ finaldict.update({inverselist[i]:titledict.values()[i]})
+
- return finaldict.values()
+ return finaldict.keys()
@property
@@ -352,14 +416,68 @@ class NID(models.Model):
version = Version.objects.get(id=self.id)
return version.serialized_data
+
+
+ # def get_Version_graph_json(self,ssid):
+
+
+ # # # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"}
+ # # slist=self.get_ssid
+ # ver_dict=self.version_info(ssid)
+ # #ver_dict=str(ver['nbhood'])
+ # ver_dict=ast.literal_eval(ver_dict['nbhood'])
+
+ # g_json = {}
+ # g_json["node_metadata"]= []
+ # predicate_id = {}
+ # counter = 1
+ # for key in ver_dict.keys():
+ # val = "a" + str(counter)
+ # predicate_id[key] = val
+ # counter = counter + 1
+ # #print predicate_id
+
+ # attr_counter = -1
+
+ # this_node = {"_id":str(self.id),"title":ver_dict['title'],"screen_name":ver_dict['title'], "url":self.get_absolute_url()}
+ # g_json["node_metadata"].append(this_node)
+
+ # for key in predicate_id.keys():
+ # if ver_dict[key]:
+ # try:
+ # g_json[str(key)]=[]
+ # g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key})
+ # g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 })
+ # if not isinstance(ver_dict[key],basestring):
+ # for item in ver_dict[key]:
+ # # user
+ # g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title, "title":item.title, "url":item.get_absolute_url()})
+ # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 })
+
+ # else:
+ # #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"}
+ # #this_node[str(key)]=nbh[key] key, nbh[key]
+ # #for item in value.keys():
+ # g_json["node_metadata"].append({"_id":attr_counter,"screen_name":ver_dict[key]})
+ # g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 })
+ # attr_counter-=1
+
+ # except:
+ # pass
+ # # print g_json
+
+
+
+ # return json.dumps(g_json)
+
+
def __unicode__(self):
return self.title
class Meta:
"""NID's Meta"""
-
-
+
class Node(NID):
"""
@@ -379,7 +497,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.")
+ nbhood = models.TextField(help_text="The rendered neighbourhood of the model.")
+ # nbh = models.TextField(help_text="The neighbourhood of the model.")
published = NodePublishedManager()
def __unicode__(self):
@@ -387,16 +506,9 @@ class Node(NID):
class Meta:
abstract=False
-
+
+
- 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):
@@ -445,7 +557,7 @@ class Metatype(Node):
nbh['typeof'] = self.parent
# generate ids and names of children/members
nbh['contains_subtypes'] = self.children.get_query_set()
- nbh['contains_members'] = self.nodetypes.all()
+ nbh['contains_members'] = self.nodetypes_published()
nbh['left_subjecttype_of'] = Relationtype.objects.filter(left_subjecttype=self.id)
nbh['right_subjecttype_of'] = Relationtype.objects.filter(right_subjecttype=self.id)
nbh['attributetypes'] = Attributetype.objects.filter(subjecttype=self.id)
@@ -543,23 +655,38 @@ class Metatype(Node):
"""
Returns the neighbourhood of the metatype
"""
+ history=[]
+ version_list=self.get_ssid
+ if version_list:
+ length=len(version_list)
+ history_ssid=version_list[length-1]
+ history_dict=self.version_info(history_ssid)
+ history_nbh_dict=ast.literal_eval(history_dict['nbhood'])
+ #ssid_current.append(history_ssid)
+ history=history_nbh_dict['history']
+ history.append(history_ssid)
+ else:
+ history.append(0)
nbh = {}
+ history_list=self.get_ssid
nbh['title'] = self.title
nbh['altnames'] = self.altnames
nbh['plural'] = self.plural
if self.parent:
- nbh['typeof'] = self.parent
+ obj=NID.objects.get(id=self.parent)
+ typeof[parent] = obj.ref.get_absolute_url()
+ #nbh['typeof'] = self.parent
# generate ids and names of children
nbh['contains_subtypes'] = self.children.get_query_set()
contains_members_list = []
- for each in self.nodetypes.all():
+ for each in self.nodetypes_published():
contains_members_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title))
nbh['contains_members'] = contains_members_list
nbh['left_subjecttype_of'] = Relationtype.objects.filter(left_subjecttype=self.id)
nbh['right_subjecttype_of'] = Relationtype.objects.filter(right_subjecttype=self.id)
nbh['attributetypes'] = Attributetype.objects.filter(subjecttype=self.id)
-
+ nbh['history']=history
return nbh
@@ -568,7 +695,7 @@ class Metatype(Node):
def tree_path(self):
"""Return metatype's tree path, by its ancestors"""
if self.parent:
- return '%s/%s' % (self.parent.tree_path, self.slug)
+ return u'%s/%s' % (self.parent.tree_path, self.slug)
return self.slug
def __unicode__(self):
@@ -578,8 +705,8 @@ class Metatype(Node):
def composed_sentence(self):
"composes the relation as a sentence in triple format."
if self.parent:
- return '%s is a kind of %s' % (self.title, self.parent.tree_path)
- return '%s is a root node' % (self.slug)
+ return u'%s is a kind of %s' % (self.title, self.parent.tree_path)
+ return u'%s is a root node' % (self.slug)
@models.permalink
@@ -597,11 +724,13 @@ class Metatype(Node):
# Save for metatype
def save(self, *args, **kwargs):
+ super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method.
+ self.nbhood=self.get_rendered_nbh
+
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.
- super(Metatype, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -700,8 +829,8 @@ class Nodetype(Node):
reltypes['possible_rightroles'] = right_subset
return reltypes
-
-
+
+
@property
def get_possible_attributetypes(self):
"""
@@ -759,37 +888,8 @@ class Nodetype(Node):
rels['possible_rightroles'] = right_subset
return rels
-
-
-
- @property
- def get_possible_attributes(self):
- """
- Gets the relations possible for this metatype
- 1. Recursively create a set of all the ancestors i.e. parent/subtypes of the MT.
- 2. Get all the RT's linked to each ancestor
- """
- #Step 1.
- ancestor_list = []
- this_parent = self.parent
- # recursive thru parent field and append
- while this_parent:
- ancestor_list.append(this_parent)
- this_parent = this_parent.parent
-
- #Step 2.
- attrs = []
-
- for each in ancestor_list:
- # retrieve all the AT's from each ancestor
- attrs.extend(Attribute.objects.filter(subject=each.id))
-
- return attrs
-
-
-
-
+
def get_graph_json(self):
@@ -797,7 +897,7 @@ class Nodetype(Node):
g_json = {}
g_json["node_metadata"]= []
g_json["relations"]=[]
- g_json["relset"]=[]
+
global counter
global attr_counter
@@ -814,7 +914,7 @@ class Nodetype(Node):
this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url(),"expanded":"true"}
g_json["node_metadata"].append(this_node)
- g_json["relset"].append(self.id)
+
for key in predicate_id.keys():
if nbh[key]:
@@ -834,7 +934,7 @@ class Nodetype(Node):
# create nodes
g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url(),"expanded":"false"})
- g_json["relset"].append(item.id)
+
# g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 })
@@ -867,21 +967,49 @@ class Nodetype(Node):
pass
#print g_json
- return json.dumps(g_json)
+ return json.dumps(g_json)
+
+ @property
+ def get_possible_attributes(self):
+ """
+ Gets the relations possible for this metatype
+ 1. Recursively create a set of all the ancestors i.e. parent/subtypes of the MT.
+ 2. Get all the RT's linked to each ancestor
+ """
+ #Step 1.
+ ancestor_list = []
+ this_parent = self.parent
+
+ # recursive thru parent field and append
+ while this_parent:
+ ancestor_list.append(this_parent)
+ this_parent = this_parent.parent
+
+ #Step 2.
+ attrs = []
+
+ for each in ancestor_list:
+ # retrieve all the AT's from each ancestor
+ attrs.extend(Attribute.objects.filter(subject=each.id))
+
+ return attrs
+
+
+
@property
def tree_path(self):
"""Return nodetype's tree path, by its ancestors"""
if self.parent:
- return '%s/%s' % (self.parent.tree_path, self.slug)
+ return u'%s/%s' % (self.parent.tree_path, self.slug)
return self.slug
@property
def tree_path_sentence(self):
""" Return the parent of the nodetype in a triple form """
if self.parent:
- return '%s is a kind of %s' % (self.title, self.parent.tree_path)
- return '%s is a root node' % (self.title)
+ return u'%s is a kind of %s' % (self.title, self.parent.tree_path)
+ return u'%s is a root node' % (self.title)
@property
@@ -919,7 +1047,7 @@ class Nodetype(Node):
return relations
@property
- def get_relations1(self):
+ def get_rendered_relations(self):
"""
Returns all the relations of the nodetype
"""
@@ -943,7 +1071,7 @@ class Nodetype(Node):
if each.relationtype.title==key:
fl=1
predicate_values.append(predicate)
- reltype[key]=predicate_values
+ reltype[key]=predicate_values
if fl==0:
predicate_values=predicate
reltype[relation]=predicate_values
@@ -983,6 +1111,7 @@ class Nodetype(Node):
relations['rrelations']=reltype
return relations
+
@property
def get_attributes(self):
attributes_dict = {}
@@ -1008,19 +1137,37 @@ class Nodetype(Node):
val.extend(value)
attributes_dict[atr_key]=val
return attributes_dict
-
+
+ # def history(self,ssid):
+ #ver
@property
def get_rendered_nbh(self):
"""
Returns the neighbourhood of the nodetype
"""
+ history=[]
+ version_list=self.get_ssid
+ if version_list:
+ length=len(version_list)
+ history_ssid=version_list[length-1]
+ history_dict=self.version_info(history_ssid)
+ history_nbh_dict=ast.literal_eval(history_dict['nbhood'])
+ #ssid_current.append(history_ssid)
+ history=history_nbh_dict['history']
+ history.append(history_ssid)
+ else:
+ history.append(0)
nbh = {}
nbh['title'] = self.title
nbh['count_title'] = len(nbh['title'])
nbh['altnames'] = self.altnames
nbh['count_altnames'] = len(nbh['altnames'])
- nbh['plural'] = self.plural
- nbh['count_plural'] = len(nbh['plural'])
+ nbh['plural'] = self.plural
+ try:
+ nbh['count_plural'] = len(nbh['plural'])
+ except:
+ pass
+
#get all MTs
member_of_dict = {}
for each in self.metatypes.all():
@@ -1072,8 +1219,8 @@ class Nodetype(Node):
relns={}
rellft={}
relrgt={}
- if self.get_relations1:
- NTrelns=self.get_relations1
+ if self.get_rendered_relations:
+ NTrelns=self.get_rendered_relations
for key,value in NTrelns.items():
if key=="rrelations":
relrgt={}
@@ -1081,7 +1228,7 @@ class Nodetype(Node):
relnvalue={}
if isinstance(rgtvalue,list):
for items in rgtvalue:
- relnvalue[items]=items.get_absolute_url()
+ relnvalue[items.title]=items.get_absolute_url()
else:
relnvalue[rgtvalue]=rgtvalue.get_absolute_url()
@@ -1094,7 +1241,7 @@ class Nodetype(Node):
relnvalue={}
if isinstance(lftvalue,list):
for items in lftvalue:
- relnvalue[items]=items.get_absolute_url()
+ relnvalue[items.title]=items.get_absolute_url()
else:
relnvalue[lftvalue]=lftvalue.get_absolute_url()
@@ -1124,7 +1271,7 @@ class Nodetype(Node):
rightroles[each.title]=each.get_absolute_url()
nbh['rightroles']=rightroles
nbh['count_rightroles'] = len(nbh['rightroles'])
-
+ nbh['history']=history
return nbh
@@ -1209,22 +1356,22 @@ class Nodetype(Node):
if self.metatypes.count:
for each in self.metatypes.all():
- return '%s is a member of metatype %s' % (self.title, each)
- return '%s is not a fully defined name, consider making it a member of a suitable metatype' % (self.title)
+ return u'%s is a member of metatype %s' % (self.title, each)
+ return u'%s is not a fully defined name, consider making it a member of a suitable metatype' % (self.title)
@property
def subtypeof_sentence(self):
"composes the relation as a sentence in triple format."
if self.parent:
- return '%s is a subtype of %s' % (self.title, self.parent.tree_path)
- return '%s is a root node' % (self.title)
+ return u'%s is a subtype of %s' % (self.title, self.parent.tree_path)
+ return u'%s is a root node' % (self.title)
composed_sentence = property(subtypeof_sentence)
def subtypeof(self):
"retuns the parent nodetype."
if self.parent:
- return '%s' % (self.parent.tree_path)
+ return u'%s' % (self.parent.tree_path)
return None
@models.permalink
@@ -1235,6 +1382,9 @@ class Nodetype(Node):
'month': self.creation_date.strftime('%m'),
'day': self.creation_date.strftime('%d'),
'slug': self.slug})
+ def get_version_url(self):
+ """Return nodetype's URL"""
+ return "/nodetypes/display/viewhistory/"
def get_serialized_data(self):
"""
@@ -1252,16 +1402,7 @@ class Nodetype(Node):
verbose_name_plural = _('node types')
permissions = (('can_view_all', 'Can view all'),
('can_change_author', 'Can change author'), )
-
- # Save for nodetype
- 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.
-
-
-
+
class Objecttype(Nodetype):
'''
Object class
@@ -1269,11 +1410,7 @@ class Objecttype(Nodetype):
def __unicode__(self):
return self.title
-
-
-
-
-
+
@property
def get_attributetypes(self):
@@ -1375,61 +1512,190 @@ class Objecttype(Nodetype):
#nbh['authors'] = self.authors.all()
return nbh
-
@property
def get_rendered_nbh(self):
+ """
+ Returns the neighbourhood of the nodetype
"""
- Returns the neighbourhood of the nodetype with the hyperlinks of nodes rendered
- """
+ history=[]
+ version_list=self.get_ssid
+ if version_list:
+ length=len(version_list)
+ history_ssid=version_list[length-1]
+ history_dict=self.version_info(history_ssid)
+ history_nbh_dict=ast.literal_eval(history_dict['nbhood'])
+ #ssid_current.append(history_ssid)
+ history=history_nbh_dict['history']
+ history.append(history_ssid)
+ else:
+ history.append(0)
nbh = {}
nbh['title'] = self.title
+ nbh['count_title'] = len(nbh['title'])
nbh['altnames'] = self.altnames
- nbh['plural'] = self.plural
- member_of_metatypes_list = []
+ nbh['count_altnames'] = len(nbh['altnames'])
+ nbh['plural'] = self.plural
+ #nbh['count_plural'] = len(nbh['plural'])
+ #get all MTs
+ member_of_dict = {}
for each in self.metatypes.all():
- member_of_metatypes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title))
- nbh['member_of_metatypes'] = member_of_metatypes_list
-
-
- attributetypes_list = []
- for each in self.get_attributetypes:
- attributetypes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title))
- nbh['attributetypes'] = attributetypes_list
-
-
- # get all the RTs for the objecttype
- reltypes_list = []
- for each in self.get_relationtypes:
- reltypes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title))
- nbh['relationtypes'] = reltypes_list
-
- nbh['type_of'] = self.parent
-
- nbh['contains_subtypes'] = Nodetype.objects.filter(parent=self.id)
- # get all the objects inheriting this OT
- contains_members_list = []
- for each in self.gbobjects.all():
- contains_members_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title))
- nbh['contains_members'] = contains_members_list
-
- prior_nodes_list = []
+ member_of_dict[each.title]= each.get_absolute_url()
+ nbh['member_of_metatypes']=member_of_dict
+ nbh['count_member_of_metatypes'] = len(nbh['member_of_metatypes'])
+ typeof={}
+ parent=self.parent_id
+ if parent:
+ obj=NID.objects.get(id=parent)
+ typeof[parent] = obj.ref.get_absolute_url()
+ nbh['type_of']=typeof
+ nbh['count_type_of'] = len(nbh['type_of'])
+ #get all subtypes
+ subtypes={}
+ for each in Nodetype.objects.filter(parent=self.id):
+ subtypes[each.title] =each.get_absolute_url()
+ nbh['contains_subtypes']=subtypes
+ nbh['count_contains_subtypes'] = len(nbh['contains_subtypes'])
+ # get all the objects inheriting this OT
+ contains_members_dict = {}
+ for each in self.member_objects.all():
+ contains_members_dict[each.title]= each.get_absolute_url()
+ nbh['contains_members'] = contains_members_dict
+ nbh['count_contains_members'] = len(nbh['contains_members'])
+ #get prior nodes
+ priornodes_dict = {}
for each in self.prior_nodes.all():
- prior_nodes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title))
- nbh['prior_nodes'] = prior_nodes_list
-
- posterior_nodes_list = []
+ priornodes_dict[each.title]= each.get_absolute_url()
+ nbh['priornodes'] = priornodes_dict
+ nbh['count_priornodes'] = len(nbh['priornodes'])
+ #get posterior nodes
+ posteriornodes_dict = {}
for each in self.posterior_nodes.all():
- posterior_nodes_list.append('<a href="%s">%s</a>' % (each.get_absolute_url(), each.title))
- nbh['posterior_nodes'] = posterior_nodes_list
-
- author_list = []
+ posteriornodes_dict[each.title]= each.get_absolute_url()
+ nbh['posteriornodes'] = posteriornodes_dict
+ nbh['count_posteriornodes'] = len(nbh['posteriornodes'])
+ #get authors
+ author_dict = {}
for each in self.authors.all():
- author_list.append('<a href="%s"></a>' % (each.get_absolute_url()))
- nbh['authors'] = author_list
+ author_dict['User'] = each.get_absolute_url()
+ nbh['authors'] = author_dict
+ #get siblings
+ siblings={}
+ for each in self.get_siblings():
+ siblings[each.title]=each.get_absolute_url()
+ nbh['siblings']=siblings
+ nbh['count_siblings'] = len(nbh['siblings'])
+ #get Relations
+ relns={}
+ rellft={}
+ relrgt={}
+ if self.get_rendered_relations:
+ NTrelns=self.get_rendered_relations
+ for key,value in NTrelns.items():
+ if key=="rrelations":
+ relrgt={}
+ for rgtkey,rgtvalue in value.items():
+ relnvalue={}
+ if isinstance(rgtvalue,list):
+ for items in rgtvalue:
+ relnvalue[items.title]=items.get_absolute_url()
+ else:
+ relnvalue[rgtvalue]=rgtvalue.get_absolute_url()
+
+ relrgt[rgtkey]=relnvalue
+
+ else:
+ rellft={}
+ relns['left']=rellft
+ for lftkey,lftvalue in value.items():
+ relnvalue={}
+ if isinstance(lftvalue,list):
+ for items in lftvalue:
+ relnvalue[items.title]=items.get_absolute_url()
+ else:
+ relnvalue[lftvalue]=lftvalue.get_absolute_url()
+
+ rellft[lftkey]=relnvalue
+
+ nbh['relations']=relrgt
+
+ nbh['relations'].update(rellft)
+ nbh['count_relations'] = len(nbh['relations'])
+ #get Attributes
+ attributes =self.get_attributes
+ nbh['attributes']=attributes
+ nbh['count_attributes'] = len(nbh['attributes'])
+ #get ATs
+ attributetypes={}
+ for each in self.subjecttype_of.all():
+ attributetypes[each.title]=each.get_absolute_url()
+ nbh['ats']=attributetypes
+ #get RTs as leftroles and rightroles
+ leftroles = {}
+ for each in self.left_subjecttype_of.all():
+ leftroles[each.title]=each.get_absolute_url()
+ nbh['leftroles']=leftroles
+ nbh['count_leftroles'] = len(nbh['leftroles'])
+ rightroles = {}
+ for each in self.right_subjecttype_of.all():
+ rightroles[each.title]=each.get_absolute_url()
+ nbh['rightroles']=rightroles
+ nbh['count_rightroles'] = len(nbh['rightroles'])
+ nbh['history']=history
return nbh
+
+ def get_Version_graph_json(self,ssid):
+
+
+ # # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"}
+ # slist=self.get_ssid
+ ver_dict=self.version_info(ssid)
+ ver_dict1=self.version_info(ssid)
+ #ver_dict=str(ver['nbhood'])
+ ver_dict=ast.literal_eval(ver_dict['nbhood'])
+ g_json = {}
+ g_json["node_metadata"]= []
+ predicate_id = {}
+ counter = 1
+ for key in ver_dict.keys():
+ val = "a" + str(counter)
+ predicate_id[key] = val
+ counter = counter + 1
+ #print predicate_id
+
+ attr_counter = -1
+
+ this_node = {"_id":str(self.id),"title":ver_dict['title'],"screen_name":ver_dict['title'], "url":self.get_absolute_url()}
+ g_json["node_metadata"].append(this_node)
+
+ for key in predicate_id.keys():
+ if ver_dict[key]:
+ try:
+ g_json[str(key)]=[]
+ g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key})
+ g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 })
+ if not isinstance(ver_dict[key],basestring):
+ for item in ver_dict[key]:
+ # user
+ g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title, "title":item.title, "url":item.get_absolute_url()})
+ g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 })
+
+ else:
+ #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"}
+ #this_node[str(key)]=nbh[key] key, nbh[key]
+ #for item in value.keys():
+ g_json["node_metadata"].append({"_id":attr_counter,"screen_name":ver_dict[key]})
+ g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 })
+ attr_counter-=1
+
+ except:
+ pass
+ # print g_json
-
-
+
+
+ return json.dumps(g_json)
+
+
class Meta:
"""
object type's meta class
@@ -1441,14 +1707,22 @@ class Objecttype(Nodetype):
# Save for Objecttype
# @reversion.create_revision()
- def save(self, *args, **kwargs):
+ def save(self,*args, **kwargs):
self.nodemodel = self.__class__.__name__
+ super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method.
+ self.nbhood=self.get_rendered_nbh
+ if GSTUDIO_VERSIONING:
+ with reversion.create_revision():
+ self.nodemodel = self.__class__.__name__
+ if self.parent:
+ ot=NID.objects.get(id=self.parent.id)
+ ot.ref.save()
+ super(Objecttype, self).save(*args, **kwargs) # Call the "real" save() method.
+
+ def save_revert_or_merge(self,*args, **kwargs):
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.
-
@@ -1482,6 +1756,171 @@ class Relationtype(Nodetype):
def __unicode__(self):
return self.title
+ @property
+
+ def get_rendered_nbh(self):
+ """
+ Returns the neighbourhood of the Relationtype
+ """
+ history=[]
+ version_list=self.get_ssid
+ if version_list:
+ length=len(version_list)
+ history_ssid=version_list[length-1]
+ history_dict=self.version_info(history_ssid)
+ history_nbh_dict=ast.literal_eval(history_dict['nbhood'])
+ #ssid_current.append(history_ssid)
+ history=history_nbh_dict['history']
+ history.append(history_ssid)
+ else:
+ history.append(0)
+ nbh = {}
+ nbh['title'] = self.title
+ nbh['count_title'] = len(nbh['title'])
+ nbh['altnames'] = self.altnames
+ nbh['count_altnames'] = len(nbh['altnames'])
+ nbh['plural'] = self.plural
+# nbh['count_plural'] = len(nbh['plural'])
+ #get all MTs
+ member_of_dict = {}
+ for each in self.metatypes.all():
+ member_of_dict[each.title]= each.get_absolute_url()
+ nbh['member_of_metatypes']=member_of_dict
+ nbh['count_member_of_metatypes'] = len(nbh['member_of_metatypes'])
+ typeof={}
+ parent=self.parent_id
+ if parent:
+ obj=NID.objects.get(id=parent)
+ typeof[parent] = obj.ref.get_absolute_url()
+ nbh['type_of']=typeof
+ nbh['count_type_of'] = len(nbh['type_of'])
+ #get all subtypes
+ subtypes={}
+ for each in Nodetype.objects.filter(parent=self.id):
+ subtypes[each.title] =each.get_absolute_url()
+ nbh['contains_subtypes']=subtypes
+ nbh['count_contains_subtypes'] = len(nbh['contains_subtypes'])
+ # get all the objects inheriting this OT
+ contains_members_dict = {}
+ for each in self.member_objects.all():
+ contains_members_dict[each.title]= each.get_absolute_url()
+ nbh['contains_members'] = contains_members_dict
+ nbh['count_contains_members'] = len(nbh['contains_members'])
+ #get prior nodes
+ priornodes_dict = {}
+ for each in self.prior_nodes.all():
+ priornodes_dict[each.title]= each.get_absolute_url()
+ nbh['priornodes'] = priornodes_dict
+ nbh['count_priornodes'] = len(nbh['priornodes'])
+ #get posterior nodes
+ posteriornodes_dict = {}
+ for each in self.posterior_nodes.all():
+ posteriornodes_dict[each.title]= each.get_absolute_url()
+ nbh['posteriornodes'] = posteriornodes_dict
+ nbh['count_posteriornodes'] = len(nbh['posteriornodes'])
+ #get authors
+ author_dict = {}
+ for each in self.authors.all():
+ author_dict['User'] = each.get_absolute_url()
+ nbh['authors'] = author_dict
+ #get siblings
+ siblings={}
+ for each in self.get_siblings():
+ siblings[each.title]=each.get_absolute_url()
+ nbh['siblings']=siblings
+ nbh['count_siblings'] = len(nbh['siblings'])
+ #get Relations
+ relns={}
+ rellft={}
+ relrgt={}
+ if self.get_rendered_relations:
+ NTrelns=self.get_rendered_relations
+ for key,value in NTrelns.items():
+ if key=="rrelations":
+ relrgt={}
+ for rgtkey,rgtvalue in value.items():
+ relnvalue={}
+ if isinstance(rgtvalue,list):
+ for items in rgtvalue:
+ relnvalue[items]=items.get_absolute_url()
+ else:
+ relnvalue[rgtvalue]=rgtvalue.get_absolute_url()
+
+ relrgt[rgtkey]=relnvalue
+
+ else:
+ rellft={}
+ relns['left']=rellft
+ for lftkey,lftvalue in value.items():
+ relnvalue={}
+ if isinstance(lftvalue,list):
+ for items in lftvalue:
+ relnvalue[items]=items.get_absolute_url()
+ else:
+ relnvalue[lftvalue]=lftvalue.get_absolute_url()
+
+ rellft[lftkey]=relnvalue
+
+ nbh['relations']=relrgt
+
+ nbh['relations'].update(rellft)
+ nbh['count_relations'] = len(nbh['relations'])
+ #get Attributes
+ attributes =self.get_attributes
+ nbh['attributes']=attributes
+ nbh['count_attributes'] = len(nbh['attributes'])
+ #get ATs
+ attributetypes={}
+ for each in self.subjecttype_of.all():
+ attributetypes[each.title]=each.get_absolute_url()
+ nbh['ats']=attributetypes
+ #get RTs as leftroles and rightroles
+ leftroles = {}
+ for each in self.left_subjecttype_of.all():
+ leftroles[each.title]=each.get_absolute_url()
+ nbh['leftroles']=leftroles
+ nbh['count_leftroles'] = len(nbh['leftroles'])
+ rightroles = {}
+ for each in self.right_subjecttype_of.all():
+ rightroles[each.title]=each.get_absolute_url()
+ nbh['rightroles']=rightroles
+ nbh['count_rightroles'] = len(nbh['rightroles'])
+ nbh['history']=history
+ return nbh
+
+
+
+ def get_nbh(self):
+ """
+ Returns the neighbourhood of the nodetype
+ """
+ nbh = {}
+ nbh['title'] = self.title
+ nbh['altnames'] = self.altnames
+ nbh['plural'] = self.plural
+
+ nbh['contains_subtypes'] = Nodetype.objects.filter(parent=self.id)
+ # get all the objects inheriting this OT
+ nbh['contains_members'] = self.member_objects.all()
+ nbh['prior_nodes'] = self.prior_nodes.all()
+ nbh['posterior_nodes'] = self.posterior_nodes.all()
+ nbh['inverse']=self.inverse
+ nbh['left_subjecttype']=self.left_subjecttype
+ nbh['left_applicable_nodetypes']=self.left_applicable_nodetypes
+ nbh['left_cardinality']=self.left_cardinality
+ nbh['right_subjecttype']=self.right_subjecttype
+ nbh['right_applicable_nodetypes']=self.right_applicable_nodetypes
+ nbh['right_cardinality']=self.right_cardinality
+ nbh['is_symmetrical']=self.is_symmetrical
+ nbh['is_reflexive']=self.is_reflexive
+ nbh['is_transitive']=self.is_transitive
+
+
+
+ return nbh
+
+
+
class Meta:
"""
relation type's meta class
@@ -1495,12 +1934,12 @@ class Relationtype(Nodetype):
# @reversion.create_revision()
def save(self, *args, **kwargs):
self.nodemodel = self.__class__.__name__
+ super(Relationtype, self).save(*args, **kwargs) # Call the "real" save() method.
+ self.nbhood=self.get_rendered_nbh
if GSTUDIO_VERSIONING:
with reversion.create_revision():
self.nodemodel = self.__class__.__name__
-
-
- super(Relationtype, self).save(*args, **kwargs) # Call the "real" save() method.
+ super(Relationtype, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1534,6 +1973,140 @@ class Attributetype(Nodetype):
editable=models.NullBooleanField(verbose_name='required', null=True, blank=True, help_text='If False, the field will not be editable')
+
+ @property
+ def get_rendered_nbh(self):
+ """
+ Returns the neighbourhood of the Attributetype
+ """
+ history=[]
+ version_list=self.get_ssid
+ if version_list:
+ length=len(version_list)
+ history_ssid=version_list[length-1]
+ history_dict=self.version_info(history_ssid)
+ history_nbh_dict=ast.literal_eval(history_dict['nbhood'])
+ #ssid_current.append(history_ssid)
+ history=history_nbh_dict['history']
+ history.append(history_ssid)
+ else:
+ history.append(0)
+ nbh = {}
+ nbh['title'] = self.title
+ nbh['count_title'] = len(nbh['title'])
+ nbh['altnames'] = self.altnames
+ nbh['count_altnames'] = len(nbh['altnames'])
+ # nbh['plural'] = self.plural
+ # nbh['count_plural'] = len(nbh['plural'])
+ #get all MTs
+ member_of_dict = {}
+ for each in self.metatypes.all():
+ member_of_dict[each.title]= each.get_absolute_url()
+ nbh['member_of_metatypes']=member_of_dict
+ nbh['count_member_of_metatypes'] = len(nbh['member_of_metatypes'])
+ typeof={}
+ parent=self.parent_id
+ if parent:
+ obj=NID.objects.get(id=parent)
+ typeof[parent] = obj.ref.get_absolute_url()
+ nbh['type_of']=typeof
+ nbh['count_type_of'] = len(nbh['type_of'])
+ #get all subtypes
+ subtypes={}
+ for each in Nodetype.objects.filter(parent=self.id):
+ subtypes[each.title] =each.get_absolute_url()
+ nbh['contains_subtypes']=subtypes
+ nbh['count_contains_subtypes'] = len(nbh['contains_subtypes'])
+ # get all the objects inheriting this OT
+ contains_members_dict = {}
+ for each in self.member_objects.all():
+ contains_members_dict[each.title]= each.get_absolute_url()
+ nbh['contains_members'] = contains_members_dict
+ nbh['count_contains_members'] = len(nbh['contains_members'])
+ #get prior nodes
+ priornodes_dict = {}
+ for each in self.prior_nodes.all():
+ priornodes_dict[each.title]= each.get_absolute_url()
+ nbh['priornodes'] = priornodes_dict
+ nbh['count_priornodes'] = len(nbh['priornodes'])
+ #get posterior nodes
+ posteriornodes_dict = {}
+ for each in self.posterior_nodes.all():
+ posteriornodes_dict[each.title]= each.get_absolute_url()
+ nbh['posteriornodes'] = posteriornodes_dict
+ nbh['count_posteriornodes'] = len(nbh['posteriornodes'])
+ #get authors
+ author_dict = {}
+ for each in self.authors.all():
+ author_dict['User'] = each.get_absolute_url()
+ nbh['authors'] = author_dict
+ #get siblings
+ siblings={}
+ for each in self.get_siblings():
+ siblings[each.title]=each.get_absolute_url()
+ nbh['siblings']=siblings
+ nbh['count_siblings'] = len(nbh['siblings'])
+ #get Relations
+ relns={}
+ rellft={}
+ relrgt={}
+ if self.get_rendered_relations:
+ NTrelns=self.get_rendered_relations
+ for key,value in NTrelns.items():
+ if key=="rrelations":
+ relrgt={}
+ for rgtkey,rgtvalue in value.items():
+ relnvalue={}
+ if isinstance(rgtvalue,list):
+ for items in rgtvalue:
+ relnvalue[items]=items.get_absolute_url()
+ else:
+ relnvalue[rgtvalue]=rgtvalue.get_absolute_url()
+
+ relrgt[rgtkey]=relnvalue
+
+ else:
+ rellft={}
+ relns['left']=rellft
+ for lftkey,lftvalue in value.items():
+ relnvalue={}
+ if isinstance(lftvalue,list):
+ for items in lftvalue:
+ relnvalue[items]=items.get_absolute_url()
+ else:
+ relnvalue[lftvalue]=lftvalue.get_absolute_url()
+
+ rellft[lftkey]=relnvalue
+
+ nbh['relations']=relrgt
+
+ nbh['relations'].update(rellft)
+ nbh['count_relations'] = len(nbh['relations'])
+ #get Attributes
+ attributes =self.get_attributes
+ nbh['attributes']=attributes
+ nbh['count_attributes'] = len(nbh['attributes'])
+ #get ATs
+ attributetypes={}
+ for each in self.subjecttype_of.all():
+ attributetypes[each.title]=each.get_absolute_url()
+ nbh['ats']=attributetypes
+ #get RTs as leftroles and rightroles
+ leftroles = {}
+ for each in self.left_subjecttype_of.all():
+ leftroles[each.title]=each.get_absolute_url()
+ nbh['leftroles']=leftroles
+ nbh['count_leftroles'] = len(nbh['leftroles'])
+ rightroles = {}
+ for each in self.right_subjecttype_of.all():
+ rightroles[each.title]=each.get_absolute_url()
+ nbh['rightroles']=rightroles
+ nbh['count_rightroles'] = len(nbh['rightroles'])
+ nbh['history']=history
+
+ return nbh
+
+
def __unicode__(self):
return self.title
@@ -1557,13 +2130,17 @@ class Attributetype(Nodetype):
def save(self, *args, **kwargs):
self.nodemodel = self.__class__.__name__
-
+ super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method.
+ self.nbhood=self.get_rendered_nbh
+ if GSTUDIO_VERSIONING:
+ with reversion.create_revision():
+ super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method.
+ def save_revert_or_merge(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.
-
-
+
class Relation(Edge):
@@ -1624,12 +2201,12 @@ class Relation(Edge):
@property
def composed_sentence(self):
"composes the relation as a sentence in a triple format."
- return '%s %s %s %s %s %s' % (self.left_subject_scope, self.left_subject, self.relationtype_scope, self.relationtype, self.right_subject_scope, self.right_subject)
+ return u'%s %s %s %s %s %s' % (self.left_subject_scope, self.left_subject, self.relationtype_scope, self.relationtype, self.right_subject_scope, self.right_subject)
@property
def inversed_sentence(self):
"composes the inverse relation as a sentence in a triple format."
- return '%s %s %s %s %s' % (self.objectScope, self.right_subject, self.relationtype.inverse, self.left_subject_scope, self.left_subject )
+ return u'%s %s %s %s %s' % (self.objectScope, self.right_subject, self.relationtype.inverse, self.left_subject_scope, self.left_subject )
@property
def key_value(self):
@@ -1646,27 +2223,35 @@ class Relation(Edge):
if self.relationtype:
# for relation in self.relationtype():
- return '%s %s %s' % (self.left_subject,self.relationtype,self.right_subject )
+ return u'%s %s %s' % (self.left_subject,self.relationtype,self.right_subject )
@property
def partial_composition(self):
'''
function that composes the right_subject and relation name, as in "x as a friend", "y as a sibling"
'''
- return '%s as a %s' % (self.right_subject, self.relationtype)
+ return u'%s as a %s' % (self.right_subject, self.relationtype)
# Save for Relation
def save(self, *args, **kwargs):
+
+ """
+ left_subject and right_subject should be saved after creating the relation
+ """
self.nodemodel = self.__class__.__name__
+
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(Relation, self).save(*args, **kwargs) # Call the "real" save() method.
+ left_subject = self.left_subject
+ right_subject = self.right_subject
+ left_subject.ref.save()
+ right_subject.ref.save()
super(Relation, self).save(*args, **kwargs) # Call the "real" save() method.
-
class Attribute(Edge):
'''
Attribute value store for default datatype varchar. Subject can be any of the
@@ -1717,21 +2302,21 @@ class Attribute(Edge):
'''
composes the attribution as a sentence in a triple format.
'''
- return '%s %s has %s %s %s %s' % (self.subject_scope, self.subject, self.attributetype_scope, self.attributetype, self.value_scope, self.svalue)
+ return u'%s %s has %s %s %s %s' % (self.subject_scope, self.subject, self.attributetype_scope, self.attributetype, self.value_scope, self.svalue)
@property
def composed_attribution(self):
'''
composes a name to the attribute
'''
- return 'the %s of %s is %s' % (self.attributetype, self.subject, self.svalue)
+ return u'the %s of %s is %s' % (self.attributetype, self.subject, self.svalue)
@property
def partial_composition(self):
'''
function that composes the value and attribute name, as in "red as color", "4 as length"
'''
- return '%s as %s' % (self.svalue, self.attributetype)
+ return u'%s as %s' % (self.svalue, self.attributetype)
def subject_filter(self,attr):
@@ -1749,7 +2334,8 @@ class Attribute(Edge):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(Attribute, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(Attribute, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1766,11 +2352,14 @@ class AttributeCharField(Attribute):
# @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.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeCharField, self).save(*args, **kwargs) # Call the "real" save() method.
+
class AttributeTextField(Attribute):
@@ -1786,6 +2375,8 @@ class AttributeTextField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeTextField, self).save(*args, **kwargs) # Call the "real" save() method.
+ subject=self.subject
+ subject.ref.save()
super(AttributeTextField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1801,7 +2392,8 @@ class AttributeIntegerField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeIntegerField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1819,6 +2411,8 @@ class AttributeCommaSeparatedIntegerField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeCommaSeparatedIntegerField, self).save(*args, **kwargs) # Call the "real" save() method.
+ subject=self.subject
+ subject.ref.save()
super(AttributeCommaSeparatedIntegerField, self).save(*args, **kwargs) # Call the "real" save() method.
class AttributeBigIntegerField(Attribute):
@@ -1827,6 +2421,17 @@ class AttributeBigIntegerField(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(AttributeBigIntegerField, self).save(*args, **kwargs) # Call the "real" save() method.
+ subject=self.subject
+ subject.ref.save()
+ super(AttributeBigIntegerField, self).save(*args, **kwargs) # Call the "real" save() method.
+
class AttributePositiveIntegerField(Attribute):
@@ -1841,6 +2446,8 @@ class AttributePositiveIntegerField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributePositiveIntegerField, self).save(*args, **kwargs) # Call the "real" save() method.
+ subject=self.subject
+ subject.ref.save()
super(AttributePositiveIntegerField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1855,8 +2462,8 @@ class AttributeDecimalField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeDecimalField, self).save(*args, **kwargs) # Call the "real" save() method.
-
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeDecimalField, self).save(*args, **kwargs) # Call the "real" save() method.
class AttributeFloatField(Attribute):
@@ -1872,7 +2479,8 @@ class AttributeFloatField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeFloatField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeFloatField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1887,7 +2495,8 @@ class AttributeBooleanField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeBooleanField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeBooleanField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1904,6 +2513,8 @@ class AttributeNullBooleanField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeNullBooleanField, self).save(*args, **kwargs) # Call the "real" save() method.
+ subject=self.subject
+ subject.ref.save()
super(AttributeNullBooleanField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1919,7 +2530,8 @@ class AttributeDateField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeDateField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeDateField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1936,7 +2548,8 @@ class AttributeDateTimeField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeDateTimeField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeDateTimeField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -1953,13 +2566,14 @@ class AttributeTimeField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeTimeField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeTimeField, self).save(*args, **kwargs) # Call the "real" save() method.
class AttributeEmailField(Attribute):
- value = models.CharField(max_length=100,verbose_name='value')
+ value = models.EmailField(max_length=100,verbose_name='value')
def __unicode__(self):
return self.title
@@ -1969,13 +2583,14 @@ class AttributeEmailField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeEmailField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeEmailField, self).save(*args, **kwargs) # Call the "real" save() method.
class AttributeFileField(Attribute):
- value = models.FileField(upload_to='/media', verbose_name='file')
+ value = models.FileField(upload_to='media/'+UPLOAD_TO, verbose_name='file')
def __unicode__(self):
return self.title
@@ -1986,7 +2601,8 @@ class AttributeFileField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeFileField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeFileField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -2003,13 +2619,14 @@ class AttributeFilePathField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeFilePathField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeFilePathField, self).save(*args, **kwargs) # Call the "real" save() method.
class AttributeImageField(Attribute):
- value = models.ImageField(upload_to='/media', verbose_name='image')
+ value = models.ImageField(upload_to = UPLOAD_TO, verbose_name='image')
def __unicode__(self):
return self.title
@@ -2017,6 +2634,11 @@ class AttributeImageField(Attribute):
# @reversion.create_revision()
def save(self, *args, **kwargs):
self.nodemodel = self.__class__.__name__
+ if GSTUDIO_VERSIONING:
+ with reversion.create_revision():
+ super(AttributeImageField, self).save(*args, **kwargs) # Call the "real" save() method.
+ subject=self.subject
+ subject.ref.save()
super(AttributeImageField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -2033,7 +2655,8 @@ class AttributeURLField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeURLField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeURLField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -2050,7 +2673,8 @@ class AttributeIPAddressField(Attribute):
if GSTUDIO_VERSIONING:
with reversion.create_revision():
super(AttributeIPAddressField, self).save(*args, **kwargs) # Call the "real" save() method.
-
+ subject=self.subject
+ subject.ref.save()
super(AttributeIPAddressField, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -2080,11 +2704,13 @@ class Processtype(Nodetype):
# @reversion.create_revision()
def save(self, *args, **kwargs):
self.nodemodel = self.__class__.__name__
+ super(Processtype, self).save(*args, **kwargs) # Call the "real" save() method.
+ self.nbhood=self.get_rendered_nbh
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.
+
@@ -2121,13 +2747,12 @@ class Systemtype(Nodetype):
# @reversion.create_revision()
def save(self, *args, **kwargs):
self.nodemodel = self.__class__.__name__
+ super(Systemtype, self).save(*args, **kwargs) # Call the "real" save() method.
+ self.nbhood=self.get_rendered_nbh
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.
-
-
class AttributeSpecification(Node):
"""
@@ -2148,7 +2773,7 @@ class AttributeSpecification(Node):
subjects = u''
for each in self.subjects.all():
subjects = subjects + each.title + ' '
- return 'the %s of %s' % (self.attributetype, subjects)
+ return u'the %s of %s' % (self.attributetype, subjects)
def __unicode__(self):
@@ -2189,7 +2814,7 @@ class RelationSpecification(Node):
subjects = u''
for each in self.subjects.all():
subjects = subjects + each.title + ' '
- return 'the %s of %s' % (self.relationtype, subjects)
+ return u'the %s of %s' % (self.relationtype, subjects)
def __unicode__(self):
return self.composed_subject
@@ -2231,7 +2856,7 @@ class NodeSpecification(Node):
attributes = u''
for each in self.attributes.all():
attributes = attributes + each.partial_composition + ', '
- return 'the %s with %s, %s' % (self.subject, self.relations, self.attributes)
+ return u'the %s with %s, %s' % (self.subject, self.relations, self.attributes)
def __unicode__(self):
return self.composed_subject
@@ -2270,7 +2895,7 @@ class Expression(Node):
@property
def composed_sentence(self):
"composes the relation as a sentence in a triple format."
- return '%s %s %s' % (self.left_term, self.relationtype, self.right_term)
+ return u'%s %s %s' % (self.left_term, self.relationtype, self.right_term)
class Meta:
@@ -2355,7 +2980,7 @@ if GSTUDIO_VERSIONING == True:
reversion.register(NID)
if not reversion.is_registered(Systemtype):
- reversion.register(Systemtype)
+ reversion.register(Systemtype,follow=["nodetype_ptr"] )
if not reversion.is_registered(Objecttype):
reversion.register(Objecttype , follow=["nodetype_ptr"])
@@ -2368,7 +2993,7 @@ if GSTUDIO_VERSIONING == True:
if not reversion.is_registered(Processtype):
- reversion.register(Processtype, follow=["changing_attributetype_set", "changing_relationtype_set"])
+ reversion.register(Processtype, follow=["nodetype_ptr","changing_attributetype_set", "changing_relationtype_set"])
if not reversion.is_registered(Nodetype):
reversion.register(Nodetype, follow=["node_ptr","parent", "metatypes","prior_nodes", "posterior_nodes"])
@@ -2378,10 +3003,10 @@ if GSTUDIO_VERSIONING == True:
if not reversion.is_registered(Relationtype):
- reversion.register(Relationtype, follow=["left_subjecttype", "right_subjecttype"])
+ reversion.register(Relationtype, follow=["nodetype_ptr","left_subjecttype", "right_subjecttype"])
if not reversion.is_registered(Attributetype):
- reversion.register(Attributetype, follow=["subjecttype"])
+ reversion.register(Attributetype, follow=["nodetype_ptr","subjecttype"])
if not reversion.is_registered(Attribute):
reversion.register(Attribute, follow=["subject", "attributetype"])