Database Reference
In-Depth Information
# get the tags of user's friends
tagsInNetwork = Tag().tags_in_network(graph_db, request.get_cookie(graphstoryUserAuthKey))
# if the user's content was requested
if request.query.get('userscontent') == "true":
contents = Content().get_user_content_with_tag(graph_db,
request.get_cookie(graphstoryUserAuthKey),
request.query.get('tag'))
# if the user's friends' content was requested
else:
contents = Content().get_following_content_with_tag(graph_db,
request.get_cookie(graphstoryUserAuthKey),
request.query.get('tag'))
return template('public/templates/graphs/interest/index.html', layout=applayout,
userTags=userTags,
tagsInNetwork=tagsInNetwork, contents=contents, title="Interest")
Filtering Managed Content
Once the list of tags for the user and for the group she follows has been provided, the content can be filtered based
on the generated tag links, which is shown in Figure 9-12 . If a tag is clicked on the inside of the “My Interests” section,
then the get_user_content_with_tag method, displayed in Listing 9-33, will be called.
Listing 9-33. Get the Content of the Current User Based on a Tag
def get_user_content_with_tag(self, graph_db, username, wordPhrase):
query = neo4j.CypherQuery(graph_db,
" MATCH (u:User {username: {u} })-[:CURRENTPOST]-lp-[:NEXTPOST*0..]-p
" +
" WITH DISTINCT u,p" +
" MATCH p-[:HAS]-(t:Tag {wordPhrase : {wp} } )" +
" RETURN p.contentId as contentId, p.title as title, p.tagstr as
tagstr, " +
" p.timestamp as timestamp, p.url as url, u.username as username, true
as owner" +
" ORDER BY p.timestamp DESC")
params = {"u": username, "wp": wordPhrase}
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
Filtering Connected Content
If a tag is clicked on the inside of the “Interests in my Network” section, then get_following_content_with_tag
method will be called, as shown in Listing 9-34. The second query is nearly identical the first query found in the
interest route, except that it will factor in the users being followed and exclude the current user (Figure 9-13 ).
 
Search WWH ::




Custom Search