diff options
-rw-r--r-- | apioforum/static/style.css | 2 | ||||
-rw-r--r-- | apioforum/templates/common.html | 4 | ||||
-rw-r--r-- | apioforum/thread.py | 14 |
3 files changed, 13 insertions, 7 deletions
diff --git a/apioforum/static/style.css b/apioforum/static/style.css index 46115db..33fd433 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -28,6 +28,8 @@ body { font-family: sans-serif } .post-heading-a { margin-left: 0.2em } .post-heading-b { float: right; margin-right: 0.5em } +.post-anchor-link { color: hsl(0,0%,25%); } + .un-col-1 { color: hsl(0, 100%, 30%) } .un-col-2 { color: hsl(22.5, 100%, 30%) } .un-col-3 { color: hsl(45.0, 100%, 30%) } diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html index 461299d..2206ac3 100644 --- a/apioforum/templates/common.html +++ b/apioforum/templates/common.html @@ -1,5 +1,5 @@ {% macro disp_post(post, buttons=False) %} -<div class="post"> +<div class="post" id="post_{{post.id}}"> <div class="post-heading"> <span class="post-heading-a"> <span class="post-heading-em">{{post.author}}</span> {{ts(post.created)}} @@ -14,7 +14,7 @@ <a class="actionbutton" href="{{url_for('thread.delete_post',post_id=post.id)}}">delete</a> {% endif %} - #{{post.id}} + <a class="post-anchor-link" href="#post_{{post.id}}">#{{post.id}}</a> </span> </div> <div class="post-content"> diff --git a/apioforum/thread.py b/apioforum/thread.py index 3378982..630cb33 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -9,6 +9,9 @@ from .mdrender import render bp = Blueprint("thread", __name__, url_prefix="/thread") +def post_jump(thread_id, post_id): + return url_for("thread.view_thread",thread_id=thread_id)+"#post_"+str(post_id) + @bp.route("/<int:thread_id>") def view_thread(thread_id): db = get_db() @@ -37,17 +40,19 @@ def create_post(thread_id): elif not thread: flash("that thread does not exist") else: - db.execute( + cur = db.cursor() + cur.execute( "INSERT INTO posts (thread,author,content,created) VALUES (?,?,?,current_timestamp);", (thread_id,g.user,content) ) - db.execute( + post_id = cur.lastrowid + cur.execute( "UPDATE threads SET updated = current_timestamp WHERE id = ?;", (thread_id,) ) db.commit() flash("post posted postfully") - return redirect(url_for('thread.view_thread',thread_id=thread_id)) + return redirect(post_jump(thread_id, post_id)) @bp.route("/delete_post/<int:post_id>", methods=["GET","POST"]) def delete_post(post_id): @@ -91,12 +96,11 @@ def edit_post(post_id): err="post contents can't be empty" print(err) if err is None: - print("a") db.execute( "UPDATE posts SET content = ?, edited = 1, updated = current_timestamp WHERE id = ?",(newcontent,post_id)) db.commit() flash("post edited editiously") - return redirect(url_for("thread.view_thread",thread_id=post['thread'])) + return redirect(post_jump(post['thread'],post_id)) else: flash(err) return render_template("edit_post.html",post=post) |