aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--apioforum/templates/common.html4
-rw-r--r--apioforum/templates/history.html22
-rw-r--r--apioforum/templates/view_post.html16
-rw-r--r--apioforum/thread.py38
4 files changed, 76 insertions, 4 deletions
diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html
index 1177405..cac27ec 100644
--- a/apioforum/templates/common.html
+++ b/apioforum/templates/common.html
@@ -50,6 +50,10 @@
{% endif %}
<a class="actionbutton"
href="{{url_for('thread.view_post',post_id=post.id)}}">src</a>
+ {% if post.wiki == 1 %}
+ <a class="actionbutton"
+ href="{{url_for('thread.view_history',post_id=post.id)}}">history</a>
+ {% endif %}
{% endif %}
<a class="post-anchor-link" href="{{post_jump(post.id)}}">#{{post.id}}</a>
diff --git a/apioforum/templates/history.html b/apioforum/templates/history.html
new file mode 100644
index 0000000..2e8b1b0
--- /dev/null
+++ b/apioforum/templates/history.html
@@ -0,0 +1,22 @@
+{% from 'common.html' import disp_post, ts %}
+{% extends 'base.html' %}
+{% block header %}
+<h1>{%block title%}edit history{%endblock%}</h1>
+{% endblock %}
+
+{% block content %}
+{{disp_post(post, preview = True)}}
+<h2>edits</h2>
+<table class="history">
+{% for rev in history %}
+ <tr>
+ <td>{{disp_user(rev.author)}}
+ <td>
+ <a href="{{url_for('thread.view_post',post_id=post.id)}}?revision={{rev.id}}">
+ {{ts(rev.time)}} ago
+ </a>
+ <td>{{rev.comment}}
+{% endfor %}
+</table>
+<p><a href="{{post_jump(post.id)}}">i am satisfied</a></p>
+{% endblock %}
diff --git a/apioforum/templates/view_post.html b/apioforum/templates/view_post.html
index fcaf29b..ed8e0dd 100644
--- a/apioforum/templates/view_post.html
+++ b/apioforum/templates/view_post.html
@@ -1,12 +1,24 @@
{% from 'common.html' import disp_post %}
{% extends 'base.html' %}
{% block header %}
-<h1>{%block title%}viewing post{%endblock%}</h1>
+<h1>
+ {%block title%}
+ {% if not revision %}
+ viewing post
+ {% else %}
+ viewing revision
+ {% endif %}
+ {%endblock%}
+</h1>
{% endblock %}
{% block content %}
{{disp_post(post,False)}}
<p>post source:</p>
<textarea readonly class="new-post-box" name="newcontent">{{post.content}}</textarea>
-<a href="{{post_jump(post.id)}}">i am satisfied</a>
+{% if not revision %}
+ <a href="{{post_jump(post.id)}}">i am satisfied</a>
+{% else %}
+ <a href="{{url_for('thread.view_history',post_id=post.id)}}">i am satisfied</a>
+{% endif %}
{% endblock %}
diff --git a/apioforum/thread.py b/apioforum/thread.py
index 8911e95..189dcb7 100644
--- a/apioforum/thread.py
+++ b/apioforum/thread.py
@@ -363,7 +363,7 @@ def edit_post(post_id):
if request.method == "POST":
err = None
newcontent = request.form['newcontent']
- comment = request.form['comment'] if 'comment' in request.form else None
+ comment = request.form['comment'] if 'comment' in request.form else ""
if len(newcontent.strip()) == 0:
err="post contents can't be empty"
@@ -398,8 +398,42 @@ def view_post(post_id):
if not has_permission(post['f_id'], g.user, "p_view_threads", False):
abort(403)
- return render_template("view_post.html",post=post)
+ rev = None
+ if 'revision' in request.args:
+ rev_id = None
+ try:
+ rev_id = int(request.args['revision'])
+ except ValueError:
+ abort(404)
+ rev = db.execute("SELECT * FROM revisions WHERE id = ?;",(rev_id,)).fetchone()
+ if not rev:
+ abort(404)
+ if rev['post'] != post_id:
+ abort(404)
+ if post['wiki'] != 1:
+ abort(403)
+ post = dict(post)
+ post['content'] = rev['content']
+ post['updated'] = rev['time']
+
+ return render_template("view_post.html",post=post,revision=rev)
+@bp.route("/history/<int:post_id>")
+def view_history(post_id):
+ db = get_db()
+ post = db.execute("""
+ SELECT p.*,h.f_id FROM posts p
+ INNER JOIN forum_thread_of_post h ON p.id = h.p_id
+ WHERE p.id = ?;
+ """,(post_id,)).fetchone()
+ if post is None:
+ abort(404)
+ if not has_permission(post['f_id'], g.user, "p_view_threads", False):
+ abort(403)
+ history = db.execute("""
+ SELECT author, time, comment, id FROM revisions WHERE post = ? ORDER BY time DESC;
+ """,(post_id,)).fetchall()
+ return render_template("history.html",post=post,history=history)
def apply_selected_tags(thread, form):
db = get_db()