diff --git a/app.py b/app.py index 659b020..0a205b9 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template, request, jsonify +from flask import Flask, render_template, request, jsonify, make_response from flask_assets import Bundle, Environment from arango import ArangoClient @@ -74,7 +74,7 @@ def board_posts(board=None): 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) + return render_template("board-posts.html", host_id=docker_short_id, postos=postos, board=board, target_post_id=None) #### TODO route :: /{board}/{thread}/ @@ -111,7 +111,29 @@ def thread_posts(board=None, target_post_id=None): 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}/create_thread/{target_post_id} +@app.route("//create-thread/", methods=['POST']) +def create_thread(board=None, target_post_id=None): + + postos = db.collection('posts') + data = request.form['send_this_text'] + + metadata = postos.insert({ + 'texto': data, + "root_post": True, + 'board': board, + 'images': [], + "children_num": 0, + "answers_num": 0, + "answers_list": [ [], [], [] ] + }, overwrite_mode='update') + + response = make_response() + response.headers["HX-Redirect"] = f"/{board}/{metadata['_key']}" + response.status_code = 200 + return response + #### TODO route :: /{board}/{thread}/answer_post/ @@ -178,8 +200,7 @@ def post_to_post(post_key): print(f'somebody tried to put this inside minio: {file.filename} size: {size}') - postos = db.collection('posts') - + postos = db.collection('posts') data = request.form['send_this_text'] metadata = postos.insert({ diff --git a/templates/board-posts.html b/templates/board-posts.html index 2f729c2..3648cbe 100644 --- a/templates/board-posts.html +++ b/templates/board-posts.html @@ -5,6 +5,10 @@ {% include 'navbar.html' %} +
+{% include 'create-thread.html' %} +
+
{% include 'op-posts.html' %} diff --git a/templates/create-thread.html b/templates/create-thread.html new file mode 100644 index 0000000..b264c2d --- /dev/null +++ b/templates/create-thread.html @@ -0,0 +1,48 @@ +
+
+
+
+ Создавай тред уже! +
+
+
+ + +
+
+
+
+
+
+ File + +
+
+ + +
+ +
+
+
+
+ +
+
\ No newline at end of file diff --git a/templates/op-posts.html b/templates/op-posts.html index af8da61..ad51628 100644 --- a/templates/op-posts.html +++ b/templates/op-posts.html @@ -9,7 +9,7 @@
- #{{ posto._key }} + #{{ posto._key }} Ответов: {{ posto.answers_num }} Длина треда: {{ posto.children_num }} @@ -43,7 +43,7 @@