summaryrefslogtreecommitdiff
path: root/gstudio/models.py
diff options
context:
space:
mode:
authorcsitifr <csitifr@gmail.com>2012-05-28 18:47:06 +0530
committercsitifr <csitifr@gmail.com>2012-05-28 18:47:06 +0530
commitc1143a5cb0866541216ea5d0a6d9703af6f04e6d (patch)
tree6af5c0b1f1d081573aaf54a97770e2a53b07084b /gstudio/models.py
parentf28648fce9a224b6f4c3a24cfaf4b29082dbb775 (diff)
parentfb95ba12fbf670e232e71c2c57508687d79bc76a (diff)
downloadgnowsys-c1143a5cb0866541216ea5d0a6d9703af6f04e6d.tar.gz
Merge branch 'master' of https://github.com/gnowgi/gnowsys-studio
Conflicts: objectapp/templates/objectapp/gbobject_detail.html
Diffstat (limited to 'gstudio/models.py')
-rw-r--r--gstudio/models.py272
1 files changed, 186 insertions, 86 deletions
diff --git a/gstudio/models.py b/gstudio/models.py
index d4cdc5f..105dc7b 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):
@@ -377,6 +417,61 @@ 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)
+
+ 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(ver_dict['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
@@ -385,7 +480,6 @@ class NID(models.Model):
"""NID's Meta"""
-
class Node(NID):
"""
Super class
@@ -415,11 +509,13 @@ class Node(NID):
def save(self, *args, **kwargs):
+
+ # self.nbhood=self.get_nbh
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.
-
+
+ super(Node, self).save(*args, **kwargs) # Call the "real" save() method.
@@ -470,7 +566,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)
@@ -578,7 +674,7 @@ class Metatype(Node):
# 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)
@@ -593,7 +689,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):
@@ -603,8 +699,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
@@ -622,11 +718,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_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.
@@ -725,8 +823,8 @@ class Nodetype(Node):
reltypes['possible_rightroles'] = right_subset
return reltypes
-
-
+
+
@property
def get_possible_attributetypes(self):
"""
@@ -786,35 +884,6 @@ class Nodetype(Node):
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):
@@ -893,20 +962,47 @@ class Nodetype(Node):
#print 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
@@ -1234,22 +1330,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
@@ -1260,6 +1356,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):
"""
@@ -1284,7 +1383,7 @@ class Nodetype(Node):
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):
@@ -1468,11 +1567,12 @@ class Objecttype(Nodetype):
# @reversion.create_revision()
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_nbh
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.
+
@@ -1582,13 +1682,13 @@ class Attributetype(Nodetype):
def save(self, *args, **kwargs):
self.nodemodel = self.__class__.__name__
-
- if GSTUDIO_VERSIONING:
+
+# self.nbhood=self.get_nbh
+ 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.
-
-
+
+ super(Attributetype, self).save(*args, **kwargs) # Call the "real" save() method.
class Relation(Edge):
@@ -1649,12 +1749,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):
@@ -1671,14 +1771,14 @@ 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
@@ -1742,21 +1842,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):
@@ -2173,7 +2273,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):
@@ -2214,7 +2314,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
@@ -2256,7 +2356,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
@@ -2295,7 +2395,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: