diff --git a/app.py b/app.py index 403739a..d16f393 100644 --- a/app.py +++ b/app.py @@ -102,6 +102,43 @@ def post_a_post(post_key): return render_template("i-posts.html", host_id=docker_short_id, postos=postos) + +@app.route('/post_to_another_post/', methods=['POST']) +def post_a_post(post_key): + + + postos = db.collection('posts') + + data = request.form['send_this_text'] + + metadata = postos.insert({ + 'texto': data, + 'parent_post': f'{post_key}' + }, overwrite_mode='update') + + metadata = db.collection('post_parents').insert({ + '_from': f'posts/{post_key}', + '_to': f'posts/{metadata["_key"]}' + }, overwrite_mode='update') + + + cursor = db.aql.execute( + """FOR ppp IN posts + LET children = (FOR v IN 1..9999 OUTBOUND ppp post_parents RETURN v) + UPDATE ppp WITH { children_num : COUNT_DISTINCT( children[*]._key ) } IN posts""" + ) + cursor = db.aql.execute( + """FOR ppp IN posts + LET children = (FOR v IN 1OUTBOUND ppp post_parents RETURN v) + UPDATE ppp WITH { answers_num : COUNT_DISTINCT( children[*]._key ) } IN posts""" + ) + + postos = db.collection('posts') + postos = sorted(postos, key=lambda posto: posto['_key'], reverse=False) + + return render_template("i-posts.html", host_id=docker_short_id, postos=postos) + + # @app.route('/post_my_file', method=['POST']) # def post_a_file(): # pass diff --git a/templates/interactive-posts.html b/templates/interactive-posts.html index 2c84068..ad5832f 100644 --- a/templates/interactive-posts.html +++ b/templates/interactive-posts.html @@ -18,24 +18,17 @@ -
- -
-