From 9f8f3af43fe8ab6c3f3f5c4882ff4f325ee417b2 Mon Sep 17 00:00:00 2001 From: Kabir Date: Tue, 1 May 2012 12:42:50 +0530 Subject: Relation filter modified to include OT, thier children, members of OTs and children.Creation, updation date removed from relation form --- gstudio/views/ajaxviews.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'gstudio/views') diff --git a/gstudio/views/ajaxviews.py b/gstudio/views/ajaxviews.py index 8fbb6e03..3991a899 100644 --- a/gstudio/views/ajaxviews.py +++ b/gstudio/views/ajaxviews.py @@ -76,22 +76,37 @@ def additemdict(sdict,itemtoadd): sdict[itemtoadd.id]=itemtoadd.title return sdict def selectionlist_OT(obj): + # Basically the filter must filter out the OT, their members, the children and members of the children + global rlist # Return all OTs and members of subtypes of OT obs=Objecttype.objects.filter(title=obj) # Get all members of subtypes of each OT if obs: + # Add the items first + for each in obs: + rlist=additemdict(rlist,each) obs=Objecttype.objects.get(title=obj) + # Add the objects first + # for each in obs: + # rlist = additemdict(rlist,each) memobs=obs.get_members if memobs: for each in memobs: rlist=additemdict(rlist,each) childrenots=obs.get_children() + # Add children first + for each in childrenots: + rlist=additemdict(rlist,each) + # Add memebers of each child if childrenots: for eachchild in childrenots: membs=eachchild.ref.get_members for each in membs: rlist=additemdict(rlist,each) + + + return rlist def selectionlist_MT(obj): -- cgit v1.2.3-70-g09d2 From 45fb5f2bdda2bbe5fd6bae887a6dfa230e69bb62 Mon Sep 17 00:00:00 2001 From: shefali shetty Date: Thu, 3 May 2012 12:01:36 +0530 Subject: a gnowsys-studio/ --- gstudio/__init__.pyc | Bin 378 -> 385 bytes gstudio/models.py | 29 ++- gstudio/templates/gstudio/graph1.html | 2 +- gstudio/templates/gstudio/skeleton.html | 370 ++++++++++++-------------------- gstudio/testloop.py | 59 +++++ gstudio/urls/graphs.py | 1 + gstudio/views/graphs.py | 23 +- 7 files changed, 236 insertions(+), 248 deletions(-) create mode 100644 gstudio/testloop.py (limited to 'gstudio/views') diff --git a/gstudio/__init__.pyc b/gstudio/__init__.pyc index 9f1566a8..7069febd 100644 Binary files a/gstudio/__init__.pyc and b/gstudio/__init__.pyc differ diff --git a/gstudio/models.py b/gstudio/models.py index d793db0a..8952bdea 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -168,6 +168,10 @@ STATUS_CHOICES = ((DRAFT, _('draft')), (HIDDEN, _('hidden')), (PUBLISHED, _('published'))) + +counter = 1 +attr_counter = -1 + class Author(User): """Proxy Model around User""" @@ -691,6 +695,9 @@ class Nodetype(Node): return attrs + + + def get_graph_json(self): @@ -698,20 +705,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(): @@ -728,7 +736,7 @@ class Nodetype(Node): 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["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 @@ -738,14 +746,15 @@ class Nodetype(Node): #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 @@ -1141,7 +1150,7 @@ class Objecttype(Nodetype): def __unicode__(self): return self.title - #def get_graph_json(self): + @@ -1243,7 +1252,7 @@ class Objecttype(Nodetype): nbh['posterior_nodes'] = self.posterior_nodes.all() - nbh['authors'] = self.authors.all() + #nbh['authors'] = self.authors.all() return nbh diff --git a/gstudio/templates/gstudio/graph1.html b/gstudio/templates/gstudio/graph1.html index 587b703b..ab66e51f 100644 --- a/gstudio/templates/gstudio/graph1.html +++ b/gstudio/templates/gstudio/graph1.html @@ -94,7 +94,7 @@ $(function() { success : function(json) { var force; - + // this contains all the nodes as a dict with _id as the key var nodes_by_id = _.reduce(json.node_metadata, function(acc, n) { diff --git a/gstudio/templates/gstudio/skeleton.html b/gstudio/templates/gstudio/skeleton.html index 1fcf9ccf..1e790ff3 100644 --- a/gstudio/templates/gstudio/skeleton.html +++ b/gstudio/templates/gstudio/skeleton.html @@ -16,14 +16,14 @@ .mainnode{ font: 15px sans-serif; - fill:"red"; + fill:"black"; border-width: 1px; font-weight:bold; border-color: gray; } .relnode { - font: 10px sans-serif; + font: 12px sans-serif; font-weight:bold; fill:#000; } @@ -32,8 +32,9 @@ .node { border-width: 1px; border-color: gray; - fill:"green"; - font: 10px sans-serif; + font: 12px sans-serif; + fill:#25587E; + font-weight:bold; } body { background-color: white; @@ -45,8 +46,8 @@ display: block; } svg { - margin-left: 10%; - margin-right: 10%; + margin-left: 50%; + margin-right: 50%; display: block; position: absolute; } @@ -168,52 +169,18 @@ diff --git a/gstudio/testloop.py b/gstudio/testloop.py new file mode 100644 index 00000000..84553875 --- /dev/null +++ b/gstudio/testloop.py @@ -0,0 +1,59 @@ +import rdflib +from rdflib.graph import ConjunctiveGraph as Graph +from rdflib import plugin +from rdflib.store import Store, NO_STORE, VALID_STORE +from rdflib.namespace import Namespace +from rdflib.term import Literal +from rdflib.term import URIRef +from tempfile import mkdtemp +from gstudio.models import * + +def rdf_description(name, notation='xml' ): + """ + Funtion takes title of node, and rdf notation. + """ + valid_formats = ["xml", "n3", "ntriples", "trix"] + default_graph_uri = "http://gstudio.gnowledge.org/rdfstore" + configString = "/var/tmp/rdfstore" + + # Get the Sleepycat plugin. + store = plugin.get('IOMemory', Store)('rdfstore') + + # Open previously created store, or create it if it doesn't exist yet + graph = Graph(store="IOMemory", + identifier = URIRef(default_graph_uri)) + path = mkdtemp() + rt = graph.open(path, create=False) + if rt == NO_STORE: + #There is no underlying Sleepycat infrastructure, create it + graph.open(path, create=True) + else: + assert rt == VALID_STORE, "The underlying store is corrupt" + + + # Now we'll add some triples to the graph & commit the changes + rdflib = Namespace('http://sbox.gnowledge.org/gstudio/') + graph.bind("gstudio", "http://gnowledge.org/") + exclusion_fields = ["id", "rght", "node_ptr_id", "image", "lft", "_state", "_altnames_cache", "_tags_cache", "nid_ptr_id", "_mptt_cached_fields"] + node=NID.objects.get(title=name) + node_dict=node.__dict__ + + subject=str(node_dict['id']) + for key in node_dict: + if key not in exclusion_fields: + predicate=str(key) + pobject=str(node_dict[predicate]) + graph.add((rdflib[subject], rdflib[predicate], Literal(pobject))) + + + graph.commit() + + print graph.serialize(format=notation) + + graph.close() +i=0 +p=NID.objects.all() +for each in p: + rdf_description(p[i]) + i=i+1 + diff --git a/gstudio/urls/graphs.py b/gstudio/urls/graphs.py index 952f0214..c43b655e 100644 --- a/gstudio/urls/graphs.py +++ b/gstudio/urls/graphs.py @@ -27,5 +27,6 @@ from gstudio.settings import ALLOW_FUTURE urlpatterns = patterns( 'gstudio.views.graphs', url(r'^graph_json/(?P\d+)$','graph_json', name='graph_json_d3'), + url(r'^graph/(?P\d+)$','force_graph', name='force_graph_d3'), ) diff --git a/gstudio/views/graphs.py b/gstudio/views/graphs.py index 1adffeca..8b226e5e 100644 --- a/gstudio/views/graphs.py +++ b/gstudio/views/graphs.py @@ -73,30 +73,41 @@ from gstudio.gnowql import * #import d3 import json import os +import ast from gstudio.views.decorators import protect_nodetype from gstudio.views.decorators import update_queryset -def graph_json(request, node_id): + + +def graph_json(request, node_id): + if(node_id=='189087228'): jsonFile = open( os.path.join(os.path.dirname(__file__), '../static/gstudio/js/egonet.json'), "r") - #testjson = json.loads(jsonFile) + testjson = json.loads(jsonFile) return HttpResponse(str(jsonFile.read()), "application/json") try: node = NID.objects.get(id=node_id) - node = node.ref + node = node.ref + + except: - return HttpResponse("Node not found.", "text/html") + + return HttpResponse("node not found", "text/html") return HttpResponse(node.get_graph_json(), "application/json") - + + + + + def force_graph(request, node_id): return render_to_response('gstudio/graph1.html',{'node_id': node_id }) - + #node = get_node(str(object_id)) #ot = Objecttype.objects.get(title='place') #G = ot.get_radial_graph_json() -- cgit v1.2.3-70-g09d2 From cff95e555ab81fd93284effe6dc2995f9dc1af3a Mon Sep 17 00:00:00 2001 From: Kabir Date: Thu, 3 May 2012 21:22:07 +0530 Subject: the js file of gstudio is now called from gstudio.Filler modified to include chilren and members of the childern of subjecttypes --- demo/grappelli/templates/admin/change_form.html | 1 + gstudio/admin/attribute.py | 1 + gstudio/urls/ajaxurls.py | 2 +- gstudio/views/ajaxviews.py | 15 ++++++++++++--- 4 files changed, 15 insertions(+), 4 deletions(-) (limited to 'gstudio/views') diff --git a/demo/grappelli/templates/admin/change_form.html b/demo/grappelli/templates/admin/change_form.html index c5a26544..72282905 100644 --- a/demo/grappelli/templates/admin/change_form.html +++ b/demo/grappelli/templates/admin/change_form.html @@ -17,6 +17,7 @@ {% if change %} +