From fbb586b56cfb864b05577be4819a807888f7a0b7 Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Thu, 1 Feb 2024 03:26:12 +1000 Subject: [PATCH] threads rising --- app.py | 63 ++++++++++++++++++++++++++++++++++++-- templates/board-posts.html | 19 ++++++++++++ templates/i-posts.html | 25 ++++++++++----- templates/main-page.html | 2 +- templates/op-posts.html | 53 ++++++++++++++++++++++++++++++++ 5 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 templates/board-posts.html create mode 100644 templates/op-posts.html diff --git a/app.py b/app.py index 2be9390..659b020 100644 --- a/app.py +++ b/app.py @@ -62,7 +62,61 @@ def homepage(): board_list = [ k['_key'] for k in boards0] return render_template("main-page.html", host_id=docker_short_id, boards=board_list) - + +#### TODO если борды нет, то возвращать 404 мемную +#### TODO если треда нет, то возвращать 404 мемную + + +#### DONE route :: /{board}/ +@app.route('/') +def board_posts(board=None): + postos = db.collection('posts') + postos = [ p for p in postos if p.get('root_post') == True and p.get('board') == board ] + postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False) + + return render_template("board-posts.html", host_id=docker_short_id, postos=postos, target_post_id=None) + + +#### TODO route :: /{board}/{thread}/ +#### TODO убрать отсюда чужие рут-потсы +@app.route("//") +def thread_posts(board=None, target_post_id=None): + + ## взять рут-пост + ## взять всех его детей + + # postos = db.collection('posts') + # postos = [ p for p in postos] + # postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False) + + cursor = db.aql.execute( + f"""FOR ppp IN posts + FILTER ppp.root_post == True and ppp._key == "{target_post_id}" + FOR v IN 1 OUTBOUND ppp post_parents RETURN v""" + ) + + postos = [ ] + while not cursor.empty(): # Pop until nothing is left on the cursor. + postos.append(cursor.pop()) + cursor = db.aql.execute( + f'RETURN DOCUMENT("posts/{target_post_id}")' + ) + while not cursor.empty(): # Pop until nothing is left on the cursor. + postos.append(cursor.pop()) + postos = [ p for p in postos ] + postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False) + + if not target_post_id: + target_post_id = postos[0]['_key'] + + return render_template("interactive-posts.html", host_id=docker_short_id, postos=postos, target_post_id=target_post_id) + +#### TODO route :: /{board}/{thread}/create_thread/ + +#### TODO route :: /{board}/{thread}/answer_post/ + +#### TODO route :: /{board}/{thread}/post_to_another_post/ + @app.route('/db_posts') @app.route("/db_posts/") @@ -72,6 +126,11 @@ def page_posts_from_db(target_post_id=None): postos = [ p for p in postos] postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False) + + for p in postos: + #if p['root_post']: + print(p) + if not target_post_id: target_post_id = postos[0]['_key'] @@ -82,7 +141,7 @@ def page_posts_from_db(target_post_id=None): def answer_post(target_post_id): postos = db.collection('posts') - postos = [ p for p in postos] + postos = [ p for p in postos ] postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False) if not target_post_id: diff --git a/templates/board-posts.html b/templates/board-posts.html new file mode 100644 index 0000000..2f729c2 --- /dev/null +++ b/templates/board-posts.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block content %} + + +{% include 'navbar.html' %} + +
+
+ {% include 'op-posts.html' %} +
+ +
+ + + +{% endblock content %} \ No newline at end of file diff --git a/templates/i-posts.html b/templates/i-posts.html index 4914c35..2e9f9e2 100644 --- a/templates/i-posts.html +++ b/templates/i-posts.html @@ -17,8 +17,7 @@
{% if posto.images | length > 0 %} - + {% endif %} +
+

{{ posto.texto }}

+
+
+
+ + В тред! +
+
+
+ + + {% endfor %} +{% endif %} \ No newline at end of file