/tag/test to find posts with #test

This commit is contained in:
Socks 2018-04-05 03:20:19 +01:00
parent 1346dcfa45
commit 5abca18d04
2 changed files with 16 additions and 2 deletions

View file

@ -323,6 +323,16 @@ def messaging(user):
return redirect(request.referrer)
@app.route('/tag/<tagname>', methods=['GET'])
def findtag(tagname):
logged_in = session['username'] if ('username' in session.keys()) else False
return render_template('timeline.html',
title=str("#" + tagname),
logged_in=logged_in,
posts=timeline.find_posts_by_hashtag(tagname),
theme=accounts.get_theme(logged_in))
@app.route('/pin/<post_id>', methods=['GET'])
def pin(post_id):
if timeline.get_poster(post_id).lower() == session['username'].lower():

View file

@ -8,7 +8,7 @@ timeline_db = db.statuses
def post_status(username, content, private=False, replyTo=False, location=False):
if not content: # Don't let people post blank posts
if not content: # Don't let people post blank posts
return
currentTimeDate = datetime.datetime.now()
@ -29,7 +29,7 @@ def post_status(username, content, private=False, replyTo=False, location=False)
'reposts': [],
'replies': [],
'replyTo': ObjectId(replyTo) if replyTo else False,
'hashtags': [x for x in content.split() if x.startswith("#")],
'hashtags': [x[1:] for x in content.split() if x.startswith("#")],
'mentions': accounts_mentioned,
'location': False or location,
'private': False or private,
@ -114,5 +114,9 @@ def get_mentions(username):
return timeline_db.find({"mentions": username.lower()}).sort('timePosted', pymongo.DESCENDING)
def find_posts_by_hashtag(tag):
return timeline_db.find({'hashtags': tag})
def post_details(post_id):
return timeline_db.find_one({'_id': ObjectId(post_id)})