diff ismi-python-neo4jrestclient/ismi-vis.py @ 14:b33f35b57b93

added authors to details view.
author casties
date Mon, 05 Oct 2015 19:30:28 +0200
parents 394bd5cfc508
children ad3eefa2cb80
line wrap: on
line diff
--- a/ismi-python-neo4jrestclient/ismi-vis.py	Mon Oct 05 18:56:19 2015 +0200
+++ b/ismi-python-neo4jrestclient/ismi-vis.py	Mon Oct 05 19:30:28 2015 +0200
@@ -130,27 +130,33 @@
 @app.route("/textandcommentaries/<text_id>")
 def get_textandcommentaries(text_id):
     query = ("match (t:TEXT {ismi_id:{text_id}})"
-             " optional match (s:TEXT)<-[sr:is_commentary_on]-(t)"
-             " optional match (t)<-[cr:is_commentary_on]-(c:TEXT)" 
-             " return t,s.label, s.ismi_id,c.label,c.ismi_id")
+             " optional match (t)-[:was_created_by]->(a:PERSON)"
+             " optional match (s:TEXT)<-[:is_commentary_on]-(t)"
+             " optional match (s)-[:was_created_by]->(sa:PERSON)"
+             " optional match (t)<-[:is_commentary_on]-(c:TEXT)" 
+             " optional match (c)-[:was_created_by]->(ca:PERSON)"
+             " return t,a.label,s.label,s.ismi_id,sa.label,c.label,c.ismi_id,ca.label")
     print("query:%s"%query)
-    results = gdb.query(query, returns=(Node,str,str,str,str), 
+    results = gdb.query(query, returns=(Node,str,str,str,str,str,str,str), 
                         params={"text_id": int(text_id)})
     
     print("result:%s"%results)
     text = None
+    author = None
     scs = {}
     cs = {}
-    for [t,s_label,s_id,c_label,c_id] in results:
+    for [t,a_label,s_label,s_id,sa_label,c_label,c_id,ca_label] in results:
         text = t
+        author = a_label
         if s_id is not None and s_id != "None":
-            scs[int(s_id)] = s_label
+            scs[int(s_id)] = {"title": s_label, "author":sa_label}
             
         if c_id is not None and c_id != "None":
-            cs[int(c_id)] = c_label
+            cs[int(c_id)] = {"title": c_label, "author":ca_label}
         
     print("text:%s scs:%s cs:%s"%(text, scs, cs))
     return Response(dumps({"title": text['label'], "attrs": text.properties, 
+                           "author": author,
                            "commenting": scs, "commentaries": cs}),
                     mimetype="application/json")