diff options
author | Arun yadav <arunkumar5587@gmail.com> | 2012-05-09 16:46:57 +0530 |
---|---|---|
committer | Arun yadav <arunkumar5587@gmail.com> | 2012-05-09 16:46:57 +0530 |
commit | fe4a82b80954e4a4666afa71ab3161c8b824f9e9 (patch) | |
tree | 323a20001563644fead153a9debbc684a446a9c2 /gstudio/models.py | |
parent | 7e02e008009c476c831d7dcda78db9bc22beb42e (diff) | |
parent | 6b77378be56f722d36459056b7d3083d1a422448 (diff) | |
download | gnowsys-fe4a82b80954e4a4666afa71ab3161c8b824f9e9.tar.gz |
merged with gn repository
Diffstat (limited to 'gstudio/models.py')
-rw-r--r-- | gstudio/models.py | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/gstudio/models.py b/gstudio/models.py index 353a5b8..5129716 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -170,6 +170,10 @@ STATUS_CHOICES = ((DRAFT, _('draft')), (HIDDEN, _('hidden')), (PUBLISHED, _('published'))) + +counter = 1 +attr_counter = -1 + class Author(User): """Proxy Model around User""" @@ -802,6 +806,9 @@ class Nodetype(Node): return attrs + + + def get_graph_json(self): @@ -809,20 +816,21 @@ class Nodetype(Node): g_json = {} g_json["node_metadata"]= [] g_json["relations"]=[] - + global counter + global attr_counter nbh = self.get_nbh predicate_id = {} - counter = 1 + for key in nbh.keys(): - val = "a" + str(counter) + val = str(counter) + "a" predicate_id[key] = val counter = counter + 1 #print predicate_id - attr_counter = -1 + - this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url()} + 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) for key in predicate_id.keys(): @@ -836,27 +844,44 @@ 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()}) - - # 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 }) + 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[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":item1.id }) 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":nbh[key]}) + 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":attr_counter }) + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a")}) attr_counter-=1 except: pass #print g_json + return json.dumps(g_json) @property @@ -1261,7 +1286,7 @@ class Objecttype(Nodetype): def __unicode__(self): return self.title - #def get_graph_json(self): + @@ -1363,7 +1388,7 @@ class Objecttype(Nodetype): nbh['posterior_nodes'] = self.posterior_nodes.all() - nbh['authors'] = self.authors.all() + #nbh['authors'] = self.authors.all() return nbh |