From 8359fc42d401e37172488dc18ebfd3b7f726a978 Mon Sep 17 00:00:00 2001 From: Socks Date: Tue, 20 Feb 2018 17:04:34 +0000 Subject: [PATCH] Shows one reply further back on replies page where possible --- Tweeder.py | 5 ++++- backend/timeline.py | 7 +++++++ templates/reply.html | 31 ++++++++++++++++++++----------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Tweeder.py b/Tweeder.py index e86a735..8bdfa6e 100644 --- a/Tweeder.py +++ b/Tweeder.py @@ -135,7 +135,10 @@ def reply_to_post(post_id): if 'username' not in session.keys(): return redirect(url_for('login')) logged_in = session['username'] if ('username' in session.keys()) else False if request.method == "GET": - return render_template('reply.html', logged_in=logged_in, reply_to=timeline.post_details(post_id)) + return render_template('reply.html', + logged_in=logged_in, + reply_to=timeline.post_details(post_id), + reply_parent=timeline.get_parent(post_id)) elif request.method == "POST": timeline.post_status(logged_in, request.form['status'], replyTo=post_id) return redirect(url_for('profile')) diff --git a/backend/timeline.py b/backend/timeline.py index 4c25fbf..c1d7b36 100644 --- a/backend/timeline.py +++ b/backend/timeline.py @@ -60,3 +60,10 @@ def post_details(post_id): def delete_post(post_id): timeline_db.update_one({"_id": ObjectId(post_id)}, {'$set': {'hidden': True}}) + + +def get_parent(post_id): + if timeline_db.find_one({"_id": timeline_db.find_one({"_id": ObjectId(post_id)})['replyTo']}): + return timeline_db.find_one({"_id": timeline_db.find_one({"_id": ObjectId(post_id)})['replyTo']}) + else: + return False diff --git a/templates/reply.html b/templates/reply.html index 2b3d04d..1af7c7a 100644 --- a/templates/reply.html +++ b/templates/reply.html @@ -1,19 +1,28 @@ {% extends 'layout.html' %} {% block content %}
+
+ {% if reply_parent %} +
+
{{ reply_parent.poster }} at {{ reply_parent.timePosted.strftime('%Y-%m-%d %-H:%M') }}
+
+ {{ reply_parent.content }} +
+
+ {% endif %} -
-
Replying to {{ reply_to.poster }} at {{ reply_to.timePosted.strftime('%Y-%m-%d %-H:%M') }}
-
- {{ reply_to.content }} -
- +
+
Replying to {{ reply_to.poster }} at {{ reply_to.timePosted.strftime('%Y-%m-%d %-H:%M') }}
+
+ {{ reply_to.content }}
+ +
{% endblock %}