diff options
author | Kabir <kabir@gnowledge.org> | 2012-05-11 13:22:46 +0530 |
---|---|---|
committer | Kabir <kabir@gnowledge.org> | 2012-05-11 13:22:46 +0530 |
commit | a78bf21087bf5891a0c41fde335f4faef9d3eb0e (patch) | |
tree | 58a5d4ed47e1fe964fe39fdbfdb4e22727ab8cca /gstudio/models.py | |
parent | 0ea8ff7c34af66f2c8028ea51950f9415537c4ee (diff) | |
parent | efaedaf3619e14ecc9392a977d576eec6d33130b (diff) | |
download | gnowsys-a78bf21087bf5891a0c41fde335f4faef9d3eb0e.tar.gz |
Merge branch 'master' of https://github.com/gnowgi/gnowsys-studio
Diffstat (limited to 'gstudio/models.py')
-rw-r--r-- | gstudio/models.py | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/gstudio/models.py b/gstudio/models.py index 4e047fc..c28b81c 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -746,14 +746,15 @@ class Nodetype(Node): g_json = {} g_json["node_metadata"]= [] g_json["relations"]=[] - + g_json["relset"]=[] + global counter global attr_counter nbh = self.get_nbh predicate_id = {} for key in nbh.keys(): - val = str(counter)+"a" + val = str(counter) + "a" predicate_id[key] = val counter = counter + 1 #print predicate_id @@ -761,7 +762,8 @@ 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["node_metadata"].append(this_node) + g_json["relset"].append(self.id) for key in predicate_id.keys(): if nbh[key]: @@ -774,14 +776,32 @@ class Nodetype(Node): #g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) g_json["relations"].append({"from":self.id ,"type":str(key),"value":1,"to":predicate_id[key] }) + if not isinstance(nbh[key],basestring): for item in nbh[key]: - #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"}) + if item.reftype!="Relation": + # 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 }) + #create links + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) + + else: + + if item.left_subject.id==self.id: + item1=item.right_subject + elif item.right_subject.id==self.id: + item1=item.left_subject + + g_json["node_metadata"].append({"_id":str(item1.id),"screen_name":item1.title,"title":self.title, "url":item1.get_absolute_url(),"expanded":"false"}) - # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) - #create links - g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) + # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + #create links + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item1.id }) else: #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} @@ -789,7 +809,7 @@ class Nodetype(Node): #for item in value.keys(): g_json["node_metadata"].append({"_id":(str(attr_counter)+"a"),"screen_name":nbh[key]}) #g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) - g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a") }) + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a")}) attr_counter-=1 except: |