comparison 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
comparison
equal deleted inserted replaced
13:394bd5cfc508 14:b33f35b57b93
128 mimetype="application/json") 128 mimetype="application/json")
129 129
130 @app.route("/textandcommentaries/<text_id>") 130 @app.route("/textandcommentaries/<text_id>")
131 def get_textandcommentaries(text_id): 131 def get_textandcommentaries(text_id):
132 query = ("match (t:TEXT {ismi_id:{text_id}})" 132 query = ("match (t:TEXT {ismi_id:{text_id}})"
133 " optional match (s:TEXT)<-[sr:is_commentary_on]-(t)" 133 " optional match (t)-[:was_created_by]->(a:PERSON)"
134 " optional match (t)<-[cr:is_commentary_on]-(c:TEXT)" 134 " optional match (s:TEXT)<-[:is_commentary_on]-(t)"
135 " return t,s.label, s.ismi_id,c.label,c.ismi_id") 135 " optional match (s)-[:was_created_by]->(sa:PERSON)"
136 " optional match (t)<-[:is_commentary_on]-(c:TEXT)"
137 " optional match (c)-[:was_created_by]->(ca:PERSON)"
138 " return t,a.label,s.label,s.ismi_id,sa.label,c.label,c.ismi_id,ca.label")
136 print("query:%s"%query) 139 print("query:%s"%query)
137 results = gdb.query(query, returns=(Node,str,str,str,str), 140 results = gdb.query(query, returns=(Node,str,str,str,str,str,str,str),
138 params={"text_id": int(text_id)}) 141 params={"text_id": int(text_id)})
139 142
140 print("result:%s"%results) 143 print("result:%s"%results)
141 text = None 144 text = None
145 author = None
142 scs = {} 146 scs = {}
143 cs = {} 147 cs = {}
144 for [t,s_label,s_id,c_label,c_id] in results: 148 for [t,a_label,s_label,s_id,sa_label,c_label,c_id,ca_label] in results:
145 text = t 149 text = t
150 author = a_label
146 if s_id is not None and s_id != "None": 151 if s_id is not None and s_id != "None":
147 scs[int(s_id)] = s_label 152 scs[int(s_id)] = {"title": s_label, "author":sa_label}
148 153
149 if c_id is not None and c_id != "None": 154 if c_id is not None and c_id != "None":
150 cs[int(c_id)] = c_label 155 cs[int(c_id)] = {"title": c_label, "author":ca_label}
151 156
152 print("text:%s scs:%s cs:%s"%(text, scs, cs)) 157 print("text:%s scs:%s cs:%s"%(text, scs, cs))
153 return Response(dumps({"title": text['label'], "attrs": text.properties, 158 return Response(dumps({"title": text['label'], "attrs": text.properties,
159 "author": author,
154 "commenting": scs, "commentaries": cs}), 160 "commenting": scs, "commentaries": cs}),
155 mimetype="application/json") 161 mimetype="application/json")
156 162
157 163
158 if __name__ == '__main__': 164 if __name__ == '__main__':