aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--apioforum/templates/common.html12
-rw-r--r--apioforum/templates/history.html22
-rw-r--r--apioforum/templates/view_post.html41
-rw-r--r--apioforum/thread.py29
4 files changed, 48 insertions, 56 deletions
diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html
index c731180..ee31507 100644
--- a/apioforum/templates/common.html
+++ b/apioforum/templates/common.html
@@ -49,11 +49,13 @@
href="{{url_for('thread.delete_post',post_id=post.id)}}">delete</a>
{% endif %}
<a class="actionbutton"
- href="{{url_for('thread.view_post',post_id=post.id)}}">src</a>
- {% if post.wiki == 1 or is_admin() or g.user == post.author %}
- <a class="actionbutton"
- href="{{url_for('thread.view_history',post_id=post.id)}}">history</a>
- {% endif %}
+ href="{{url_for('thread.view_post',post_id=post.id)}}">
+ {%- if post.wiki == 1 or is_admin() or g.user == post.author -%}
+ src and history and also you can change the colour of the bike shed
+ {%- else -%}
+ src
+ {%- endif -%}
+ </a>
{% 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
deleted file mode 100644
index 48fcc97..0000000
--- a/apioforum/templates/history.html
+++ /dev/null
@@ -1,22 +0,0 @@
-{% from 'common.html' import disp_post, ts %}
-{% extends 'base.html' %}
-{% block header %}
-<h1>{%block title%}revision 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 ed8e0dd..810794e 100644
--- a/apioforum/templates/view_post.html
+++ b/apioforum/templates/view_post.html
@@ -1,24 +1,45 @@
-{% from 'common.html' import disp_post %}
+{% from 'common.html' import disp_post, ts %}
{% extends 'base.html' %}
{% block header %}
<h1>
{%block title%}
{% if not revision %}
- viewing post
+ viewing post #{{post.id}}
{% else %}
- viewing revision
+ viewing revision #{{revision.id}} of #{{post.id}}
{% 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>
-{% 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>
+
+{{disp_post(post)}}
+
+<details><summary>view post source</summary>
+<textarea readonly class="view-post-source new-post-box" name="newcontent">{{post.content}}</textarea>
+</details>
+
+{% if history %}
+<h2>revision history</h2>
+<table class="history">
+{% for rev in history %}
+ <tr>
+ <td>{{disp_user(rev.author)}}
+ <td>
+ {% if rev.id == revision.id or (loop.index == 1 and not revision) %}
+ <b>{{ts(rev.time)}} ago</b>
+ {% else %}
+ <a href="{{url_for('thread.view_post',post_id=post.id,revision=rev.id if loop.index!=1 else None)}}">
+ {{ts(rev.time)}} ago
+ </a>
+ {% endif %}
+ <td>{{rev.comment or "(no comment)"}}</td>
+{% endfor %}
+</table>
{% endif %}
+
+<p><a href="{{post_jump(post.id)}}">i am satisfied</a></p>
+
+
{% endblock %}
diff --git a/apioforum/thread.py b/apioforum/thread.py
index b679b2a..485fe01 100644
--- a/apioforum/thread.py
+++ b/apioforum/thread.py
@@ -411,6 +411,8 @@ def view_post(post_id):
if not has_permission(post['f_id'], g.user, "p_view_threads", False):
abort(403)
+ can_view_history = post['wiki'] or is_admin() or g.user == post['author']
+
rev = None
if 'revision' in request.args:
rev_id = None
@@ -418,35 +420,24 @@ def view_post(post_id):
rev_id = 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()
if not rev:
abort(404)
if rev['post'] != post_id:
abort(404)
- if post['wiki'] != 1 and not is_admin() and g.user != post['author']:
- abort(403)
post = dict(post)
post['content'] = rev['content']
post['updated'] = rev['time']
- return render_template("view_post.html",post=post,revision=rev)
+ history = None
+ if can_view_history:
+ history = db.execute("""
+ SELECT author, time, comment, id FROM revisions WHERE post = ? ORDER BY id DESC;
+ """,(post_id,)).fetchall()
-@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)
+ return render_template("view_post.html",post=post,revision=rev,history=history)
def apply_selected_tags(thread, form):
db = get_db()