Database Reference
In-Depth Information
In the case of the edit feature, you do not need to update relationships. Instead, simply retrieve the existing node
by its generated String Id (not its graph id), update its properties where necessary, and save it back to the graph.
Listing 9-30. edit_content Route and edit_content Method for a Status Update
# edit the status update
@route('/posts/edit', method='POST')
def edit_content():
# get json from the request
content = request.json
#update the status update
content=Content().edit_content(graph_db, request.get_cookie(graphstoryUserAuthKey), content)
# set response type
response.content_type = 'application/json'
# return the saved content
return dumps(content)
# edit a status update
def edit_content(self, graph_db, username, content):
tagstr=self.trim_content_tags(content["tagstr"])
tags = tagstr.split(",")
query = neo4j.CypherQuery(graph_db,
" MATCH (c:Content {contentId:{contentId}})-[:NEXTPOST*0..]-()-[:CURRENTPOST]-
(user { username: {u}}) " +
" SET c.title = {title}, c.url = {url}, c.tagstr = {tagstr}" +
" FOREACH (tagName in {tags} | " +
" MERGE (t:Tag {wordPhrase:tagName}) " +
" MERGE (c)-[:HAS]->(t) " +
" )" +
" RETURN c.contentId as contentId, c.title as title, c.tagstr as tagstr, " +
" c.timestamp as timestamp, c.url as url, {u} as username, true as owner ")
params = {"u": username, "contentId": content["contentId"],
"title": content["title"].strip(), "url": content["url"].strip(),"tagstr":tagstr,
"tags":tags}
result = query.execute(**params)
for r in result:
setattr(r, "timestampAsStr",
datetime.fromtimestamp(int(r.timestamp)).strftime('%m/%d/%Y') + " at " +
datetime.fromtimestamp(int(r.timestamp)).strftime('%I:%M %p')
)
return result
Search WWH ::




Custom Search