This commit is contained in:
parent
17fc89ebbd
commit
315e6f8142
78
app.py
78
app.py
@ -31,9 +31,9 @@ db = arango_client.db('board1', username='root', password='stolendick527')
|
|||||||
|
|
||||||
|
|
||||||
# предполагается что меняться список будет весьма редко, поэтому подхватываем при лишь при перезапуске
|
# предполагается что меняться список будет весьма редко, поэтому подхватываем при лишь при перезапуске
|
||||||
boards0 = db.collection('boards')
|
# # boards0 = db.collection('boards')
|
||||||
print(boards0)
|
# # print(boards0)
|
||||||
board_list = [ k['_key'] for k in boards0]
|
# # board_list = [ k['_key'] for k in boards0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -74,7 +74,9 @@ def board_posts(board=None):
|
|||||||
postos = [ p for p in postos if p.get('root_post') == True and p.get('board') == board ]
|
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)
|
postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False)
|
||||||
|
|
||||||
return render_template("board-posts.html", host_id=docker_short_id, postos=postos, board=board, target_post_id=None)
|
boards0 = db.collection('boards')
|
||||||
|
board_list = [ k['_key'] for k in boards0]
|
||||||
|
return render_template("board-posts.html", host_id=docker_short_id, postos=postos, board=board, target_post_id=None, boards=board_list)
|
||||||
|
|
||||||
|
|
||||||
#### TODO route :: /{board}/{thread}/
|
#### TODO route :: /{board}/{thread}/
|
||||||
@ -92,7 +94,7 @@ def thread_posts(board=None, target_post_id=None):
|
|||||||
cursor = db.aql.execute(
|
cursor = db.aql.execute(
|
||||||
f"""FOR ppp IN posts
|
f"""FOR ppp IN posts
|
||||||
FILTER ppp.root_post == True and ppp._key == "{target_post_id}"
|
FILTER ppp.root_post == True and ppp._key == "{target_post_id}"
|
||||||
FOR v IN 1 OUTBOUND ppp post_parents RETURN v"""
|
FOR v IN 1..9999 OUTBOUND ppp post_parents RETURN v"""
|
||||||
)
|
)
|
||||||
|
|
||||||
postos = [ ]
|
postos = [ ]
|
||||||
@ -109,7 +111,10 @@ def thread_posts(board=None, target_post_id=None):
|
|||||||
if not target_post_id:
|
if not target_post_id:
|
||||||
target_post_id = postos[0]['_key']
|
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)
|
|
||||||
|
boards0 = db.collection('boards')
|
||||||
|
board_list = [ k['_key'] for k in boards0]
|
||||||
|
return render_template("interactive-posts.html", board=board, host_id=docker_short_id, postos=postos, target_post_id=target_post_id, boards=board_list)
|
||||||
|
|
||||||
|
|
||||||
#### TODO route :: /{board}/create_thread/{target_post_id}
|
#### TODO route :: /{board}/create_thread/{target_post_id}
|
||||||
@ -140,44 +145,45 @@ def create_thread(board=None, target_post_id=None):
|
|||||||
#### TODO route :: /{board}/{thread}/post_to_another_post/
|
#### TODO route :: /{board}/{thread}/post_to_another_post/
|
||||||
|
|
||||||
|
|
||||||
@app.route('/db_posts')
|
# @app.route('/db_posts')
|
||||||
@app.route("/db_posts/<target_post_id>")
|
# @app.route("/db_posts/<target_post_id>")
|
||||||
def page_posts_from_db(target_post_id=None):
|
# def page_posts_from_db(target_post_id=None):
|
||||||
|
|
||||||
postos = db.collection('posts')
|
# 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)
|
# postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False)
|
||||||
|
|
||||||
|
|
||||||
for p in postos:
|
# for p in postos:
|
||||||
#if p['root_post']:
|
# #if p['root_post']:
|
||||||
print(p)
|
# print(p)
|
||||||
|
|
||||||
if not target_post_id:
|
# if not target_post_id:
|
||||||
target_post_id = postos[0]['_key']
|
# 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)
|
# return render_template("interactive-posts.html", host_id=docker_short_id, postos=postos, target_post_id=target_post_id)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/answer_post/<target_post_id>", methods=['POST'])
|
@app.route("/<board>/answer_post/<target_post_id>", methods=['POST'])
|
||||||
def answer_post(target_post_id):
|
def answer_post(board, target_post_id):
|
||||||
|
|
||||||
postos = db.collection('posts')
|
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)
|
postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False)
|
||||||
|
|
||||||
|
## ?? wut
|
||||||
if not target_post_id:
|
if not target_post_id:
|
||||||
target_post_id = postos[0]['_key']
|
target_post_id = postos[0]['_key']
|
||||||
|
|
||||||
return render_template("answer-post.html", target_post_id=target_post_id)
|
return render_template("answer-post.html", board=board, target_post_id=target_post_id)
|
||||||
|
|
||||||
|
|
||||||
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'mp4', 'webm', 'webp'}
|
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'mp4', 'webm', 'webp'}
|
||||||
def allowed_file(filename):
|
def allowed_file(filename):
|
||||||
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
||||||
|
|
||||||
@app.route('/post_to_another_post/<post_key>', methods=['POST'])
|
@app.route('/<board>/post_to_another_post/<post_key>', methods=['POST'])
|
||||||
def post_to_post(post_key):
|
def post_to_post(board, post_key):
|
||||||
|
|
||||||
|
|
||||||
#### TODO resize pics https://stackoverflow.com/questions/53337318/how-can-i-resize-image-with-pil-on-upload-and-serve-them-with-flask-cloudy
|
#### TODO resize pics https://stackoverflow.com/questions/53337318/how-can-i-resize-image-with-pil-on-upload-and-serve-them-with-flask-cloudy
|
||||||
@ -203,10 +209,25 @@ def post_to_post(post_key):
|
|||||||
postos = db.collection('posts')
|
postos = db.collection('posts')
|
||||||
data = request.form['send_this_text']
|
data = request.form['send_this_text']
|
||||||
|
|
||||||
|
|
||||||
|
cursor = db.aql.execute(
|
||||||
|
f'RETURN DOCUMENT("posts/{post_key}")'
|
||||||
|
)
|
||||||
|
p = cursor.pop()
|
||||||
|
|
||||||
|
if p.get('root_post') == True:
|
||||||
|
thread = p.get('_key')
|
||||||
|
elif not p.get('root_post'):
|
||||||
|
thread = p.get('thread')
|
||||||
|
else:
|
||||||
|
thread = 'ERROR'
|
||||||
|
|
||||||
|
print(p)
|
||||||
metadata = postos.insert({
|
metadata = postos.insert({
|
||||||
'texto': data,
|
'texto': data,
|
||||||
'parent_post': f'{post_key}',
|
'parent_post': f'{post_key}',
|
||||||
'images': []
|
'images': [],
|
||||||
|
"thread": thread
|
||||||
}, overwrite_mode='update')
|
}, overwrite_mode='update')
|
||||||
|
|
||||||
metadata = db.collection('post_parents').insert({
|
metadata = db.collection('post_parents').insert({
|
||||||
@ -215,6 +236,7 @@ def post_to_post(post_key):
|
|||||||
}, overwrite_mode='update')
|
}, overwrite_mode='update')
|
||||||
|
|
||||||
|
|
||||||
|
#### TODO оптимайз для только тредовых штук
|
||||||
cursor = db.aql.execute(
|
cursor = db.aql.execute(
|
||||||
"""FOR ppp IN posts
|
"""FOR ppp IN posts
|
||||||
LET children = (FOR v IN 1..9999 OUTBOUND ppp post_parents RETURN v)
|
LET children = (FOR v IN 1..9999 OUTBOUND ppp post_parents RETURN v)
|
||||||
@ -235,9 +257,15 @@ def post_to_post(post_key):
|
|||||||
)
|
)
|
||||||
|
|
||||||
postos = db.collection('posts')
|
postos = db.collection('posts')
|
||||||
|
postos = [ p for p in postos if (not p.get('root_post')) and p.get('thread') == thread ]
|
||||||
|
cursor = db.aql.execute(
|
||||||
|
f'RETURN DOCUMENT("posts/{thread}")'
|
||||||
|
)
|
||||||
|
postos.append(cursor.pop())
|
||||||
|
|
||||||
postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False)
|
postos = sorted(postos, key=lambda posto: int(posto['_key']), reverse=False)
|
||||||
|
|
||||||
return render_template("i-posts.html", host_id=docker_short_id, postos=postos)
|
return render_template("i-posts.html", board=board, host_id=docker_short_id, postos=postos)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
<button class="btn waves-effect waves-light"
|
<button class="btn waves-effect waves-light"
|
||||||
type="submit" name="action" hx-encoding='multipart/form-data'
|
type="submit" name="action" hx-encoding='multipart/form-data'
|
||||||
_='on htmx:xhr:progress(loaded, total) set #progress.value to (loaded/total)*100'
|
_='on htmx:xhr:progress(loaded, total) set #progress.value to (loaded/total)*100'
|
||||||
hx-post="/post_to_another_post/{{ target_post_id }}"
|
hx-post="/{{board}}/post_to_another_post/{{ target_post_id }}"
|
||||||
hx-target="#neu-posts"
|
hx-target="#neu-posts"
|
||||||
hx-include="[name='send_this_text'], [name='file']"
|
hx-include="[name='send_this_text'], [name='file']"
|
||||||
>
|
>
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
<div class="col s12 card-action white-text">
|
<div class="col s12 card-action white-text">
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<!-- <a href="#" hx-post="/post_my_post/{{ posto._key }}" hx-target="#neu-posts" >Answer me!</a> -->
|
<!-- <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="#answer-post" hx-post="/{{board}}/answer_post/{{ posto._key }}" hx-target="#answer-post" >Ответить этому.</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col s12 card-content white-text">
|
<div class="col s12 card-content white-text">
|
||||||
|
@ -15,18 +15,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col s4 ">
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
{% if boards | length > 0 %}
|
|
||||||
<p>Доски:</p>
|
|
||||||
{% for board in boards %}
|
|
||||||
<p><a href="/{{board}}" class="lime-text red collection-item" style="padding: 2px 2px;">{{board}}</a></p>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
@ -3,7 +3,12 @@
|
|||||||
<div class="nav-wrapper purple darken-3">
|
<div class="nav-wrapper purple darken-3">
|
||||||
<ul id="nav-mobile" class="left ">
|
<ul id="nav-mobile" class="left ">
|
||||||
<li> <a href="/">glavnaya</a> </li>
|
<li> <a href="/">glavnaya</a> </li>
|
||||||
<li><a href="/db_posts"><span class="new badge red" data-badge-caption="">and here we go again..</span></a> </li>
|
|
||||||
|
{% if boards | length > 0 %}
|
||||||
|
{% for board in boards %}
|
||||||
|
<li><a href="/{{board}}"><span class="new badge red" data-badge-caption="">{{board}}</span></a> </li>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
<li>
|
<li>
|
||||||
<a href="#">Вас закинуло сюда: <span class="new badge blue" data-badge-caption="">{{host_id}}</span></a>
|
<a href="#">Вас закинуло сюда: <span class="new badge blue" data-badge-caption="">{{host_id}}</span></a>
|
||||||
</li>
|
</li>
|
||||||
|
Loading…
Reference in New Issue
Block a user