threads gogogo
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simple_Not 2024-02-02 01:51:03 +10:00
parent fbb586b56c
commit 17fc89ebbd
4 changed files with 80 additions and 7 deletions

29
app.py
View File

@ -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("/<board>/create-thread/<target_post_id>", 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/
@ -179,7 +201,6 @@ def post_to_post(post_key):
postos = db.collection('posts')
data = request.form['send_this_text']
metadata = postos.insert({

View File

@ -5,6 +5,10 @@
{% include 'navbar.html' %}
<div class="row" >
{% include 'create-thread.html' %}
</div>
<div class="row" >
<div class="col s6 m5" id="op-posts">
{% include 'op-posts.html' %}

View File

@ -0,0 +1,48 @@
<div class="card">
<form
hx-encoding='multipart/form-data'
_='on htmx:xhr:progress(loaded, total) set #progress.value to (loaded/total)*100'
hx-on::after-request="this.reset()"
>
<div class="card-content">
<div class="row">
<span class="card-title">Создавай тред уже!</span>
</div>
<div class="row">
<div class="input-field col s6">
<input id="send_this_text" name="send_this_text" type="text" >
<label for="send_this_text">Печатать сюда</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<div class="file-field input-field">
<div class="btn">
<span>File</span>
<input id="file" name="file" type="file" multiple>
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="Upload one or more files">
<progress id='progress' value='0' max='100'></progress>
</div>
<!-- <div class="file-progress">
</div> -->
</div>
</div>
</div>
</div>
<div class="card-action">
<a href="/{{board}}/create-thread/{{ target_post_id }}">
<button class="btn waves-effect waves-light"
type="submit" name="action" hx-encoding='multipart/form-data'
_='on htmx:xhr:progress(loaded, total) set #progress.value to (loaded/total)*100'
hx-post="/{{board}}/create-thread/{{ target_post_id }}"
hx-include="[name='send_this_text'], [name='file']"
>
Отправить!!
<i class="material-icons right">send</i>
</button>
</a>
</div>
</form>
</div>

View File

@ -9,7 +9,7 @@
<div class="card-content white-text">
<span class="new badge yellow" data-badge-caption="">
<a class="purple-text" href="#post-{{ posto._key }}"> #{{ posto._key }} </a>
<a class="purple-text" href="/{{board}}/{{ posto._key }}"> #{{ posto._key }} </a>
</span>
<span class="new badge blue" data-badge-caption="">Ответов: {{ posto.answers_num }}</span>
<span class="new badge red" data-badge-caption="">Длина треда: {{ posto.children_num }}</span>
@ -43,7 +43,7 @@
<div class="col s12 card-action white-text">
<div class="right">
<!-- <a href="#" hx-post="/post_my_post/{{ posto._key }}" hx-target="#neu-posts" >Answer me!</a> -->
<a href="#answer-post" hx-post="/answer_post/{{ posto._key }}" hx-target="#answer-post" >В тред!</a>
<a href="/{{board}}/{{ posto._key }}" >В тред!</a>
</div>
</div>
</div>