diff --git a/apioforum/templates/view_post.html b/apioforum/templates/view_post.html index 6c3fe73..5155a67 100644 --- a/apioforum/templates/view_post.html +++ b/apioforum/templates/view_post.html @@ -25,18 +25,18 @@ {% for rev in history %} - + {% if rev.comment %}{%endif%} {% endfor %}
{{disp_user(rev.author)}} + {{disp_user(rev.editor)}} - {% if rev.id == revision.id or (loop.index == 1 and not revision) %} + {% if rev.rev_index == revision.rev_index or (loop.index == 1 and not revision) %} {{ts(rev.time)}} ago {% else %} {{ts(rev.time)}} ago {% endif %} - {{rev.comment or "(no comment)"}}{{rev.comment}}
{% endif %} diff --git a/apioforum/thread.py b/apioforum/thread.py index 485fe01..26e89e9 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -284,10 +284,6 @@ def create_post(thread_id): VALUES (?,?,?,current_timestamp,?); """,(thread_id,g.user,content,vote_id)) post_id = cur.lastrowid - cur.execute(""" - INSERT INTO revisions (post,author,content,time,comment) - VALUES (?,?,?,current_timestamp,?); - """, (post_id,g.user,content,"(created)")) cur.execute( "UPDATE threads SET updated = current_timestamp WHERE id = ?;", (thread_id,) @@ -381,14 +377,25 @@ def edit_post(post_id): if len(newcontent.strip()) == 0: err="post contents can't be empty" if err is None: - db.execute( - "UPDATE posts SET content = ?, edited = 1, updated = current_timestamp WHERE id = ?",(newcontent,post_id)) + params = dict(post_id=post_id, content=newcontent, user=g.user, comment=comment) + db.execute(""" + INSERT INTO past_revisions (post, rev_index, editor, content, time, comment) + SELECT id, rev_index, coalesce(editor,author), content, + coalesce(updated,created), comment + FROM posts WHERE id = :post_id; + """,params) db.execute(""" - INSERT INTO revisions (post, author, content, time, comment) - VALUES (?,?,?,current_timestamp,?); - """, (post_id,g.user,newcontent,comment)) - if g.user != post['author']: - db.execute("UPDATE posts SET updated_by_others = 1 WHERE id = ?",(post_id,)) + UPDATE posts SET + content = :content, + edited = 1, + updated = current_timestamp, + editor = :user, + comment = :comment, + rev_index = rev_index + 1, + et_al = et_al or author<>:user + WHERE + id = :post_id; + """,params) db.commit() flash("post edited editiously") return redirect(jump_url) @@ -415,18 +422,18 @@ def view_post(post_id): rev = None if 'revision' in request.args: - rev_id = None + rev_idx = None try: - rev_id = int(request.args['revision']) + rev_idx = int(request.args['revision']) except ValueError: abort(404) if not can_view_history: abort(403) - rev = db.execute("SELECT * FROM revisions WHERE id = ?;",(rev_id,)).fetchone() + rev = db.execute( + "SELECT * FROM past_revisions WHERE post=? and rev_index=?;", + (post_id,rev_idx)).fetchone() if not rev: abort(404) - if rev['post'] != post_id: - abort(404) post = dict(post) post['content'] = rev['content'] post['updated'] = rev['time'] @@ -434,8 +441,15 @@ def view_post(post_id): history = None if can_view_history: history = db.execute(""" - SELECT author, time, comment, id FROM revisions WHERE post = ? ORDER BY id DESC; + SELECT editor, time, comment, rev_index FROM past_revisions WHERE post = ? ORDER BY rev_index DESC; """,(post_id,)).fetchall() + history.insert(0, db.execute( + """SELECT + coalesce(editor,author) as editor, + coalesce(updated, created) as "time [timestamp]", + comment, NULL as rev_index + FROM posts WHERE id=?""",(post_id,)).fetchone()) + return render_template("view_post.html",post=post,revision=rev,history=history) -- cgit v1.2.3