From 17a3cf04913e22f2df7b14c1eb50f457c089ede7 Mon Sep 17 00:00:00 2001 From: SecretlyTaco Date: Wed, 21 Feb 2018 11:21:50 +0000 Subject: [PATCH 1/3] Implemented basic full threading, although currently gets stuck in infinite loop --- Tweeder.py | 4 ++-- backend/timeline.py | 8 ++++++++ templates/reply.html | 16 ++++++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Tweeder.py b/Tweeder.py index 8bdfa6e..a9c64cb 100644 --- a/Tweeder.py +++ b/Tweeder.py @@ -137,8 +137,8 @@ def reply_to_post(post_id): if request.method == "GET": return render_template('reply.html', logged_in=logged_in, - reply_to=timeline.post_details(post_id), - reply_parent=timeline.get_parent(post_id)) + posts=timeline.get_full_replies(post_id)[:-1], + reply_to=timeline.post_details(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 c1d7b36..34410a5 100644 --- a/backend/timeline.py +++ b/backend/timeline.py @@ -67,3 +67,11 @@ def get_parent(post_id): return timeline_db.find_one({"_id": timeline_db.find_one({"_id": ObjectId(post_id)})['replyTo']}) else: return False + +def get_full_replies(post_id): + replies = [] + replies.append(post_details(post_id)) + while get_parent(replies[-1]["_id"]): + print(replies[-1]) + replies.append(get_parent(post_id)) + return replies[::-1] diff --git a/templates/reply.html b/templates/reply.html index 1af7c7a..9e72b1c 100644 --- a/templates/reply.html +++ b/templates/reply.html @@ -2,14 +2,14 @@ {% block content %}
- {% if reply_parent %} -
-
{{ reply_parent.poster }} at {{ reply_parent.timePosted.strftime('%Y-%m-%d %-H:%M') }}
-
- {{ reply_parent.content }} -
-
- {% endif %} + {% for post in posts %} +
+
{{ post.poster }} at {{ post.timePosted.strftime('%Y-%m-%d %-H:%M') }}
+
+ {{ post.content } +
+
+ {% endfor %}
Replying to {{ reply_to.poster }} at {{ reply_to.timePosted.strftime('%Y-%m-%d %-H:%M') }}
From ebb086ecb245e3bc7ad96545e41d61f38c921f80 Mon Sep 17 00:00:00 2001 From: Socks Date: Thu, 22 Feb 2018 18:55:08 +0000 Subject: [PATCH 2/3] Fixed bug with infinite looping to get parents --- backend/timeline.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/timeline.py b/backend/timeline.py index 34410a5..2764496 100644 --- a/backend/timeline.py +++ b/backend/timeline.py @@ -74,4 +74,5 @@ def get_full_replies(post_id): while get_parent(replies[-1]["_id"]): print(replies[-1]) replies.append(get_parent(post_id)) + post_id = get_parent(post_id)['_id'] return replies[::-1] From 751e8394ea01ffe10c8f0738edcdb9a7de3ca1ef Mon Sep 17 00:00:00 2001 From: Socks Date: Thu, 22 Feb 2018 18:55:28 +0000 Subject: [PATCH 3/3] Forgot to close second } at one tag --- templates/reply.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/reply.html b/templates/reply.html index 9e72b1c..578b4ac 100644 --- a/templates/reply.html +++ b/templates/reply.html @@ -6,7 +6,7 @@
{{ post.poster }} at {{ post.timePosted.strftime('%Y-%m-%d %-H:%M') }}
- {{ post.content } + {{ post.content }}
{% endfor %}