diff options
| author | rebecca <ubq323@ubq323.website> | 2026-11-14 19:26:24 +0000 |
|---|---|---|
| committer | rebecca <ubq323@ubq323.website> | 2026-11-14 19:51:04 +0000 |
| commit | a61dea3eb69675cc4720b6575bbbde3d3fbe1aef (patch) | |
| tree | 353943c4ca16bb0872a4f246cc094b99fbb80657 | |
| parent | 39217ad599d1361194f23a12b4582b9fe00f543f (diff) | |
make revision indexes display properly
| -rw-r--r-- | apioforum/templates/common.html | 5 | ||||
| -rw-r--r-- | apioforum/templates/view_post.html | 19 | ||||
| -rw-r--r-- | apioforum/thread.py | 16 |
3 files changed, 21 insertions, 19 deletions
diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html index 7f90cfd..e9e310b 100644 --- a/apioforum/templates/common.html +++ b/apioforum/templates/common.html @@ -2,7 +2,7 @@ <a href="{{url_for('user.view_user',username=username)}}" class="username">{{username}}</a> {%- endmacro %} -{% macro disp_post(post, buttons=False, forum=None, footer=None, preview = False) %} +{% macro disp_post(post, buttons=False, forum=None, footer=None, preview=False) %} {% if not forum %} {% if post.forum %} {% set forum = post.forum %} @@ -55,8 +55,7 @@ </a> {% endif %} - <a class="post-anchor-link" href="{{post_jump(post.id)}}">#{{post.id}}</a> - {%-if buttons %}/{{post.rev_index}}{% endif -%} + <a class="post-anchor-link" href="{{post_jump(post.id)}}">#{{post.id}}</a>/{{post.rev_index}} </span> </div> <div class="post-content md"> diff --git a/apioforum/templates/view_post.html b/apioforum/templates/view_post.html index 5155a67..df27040 100644 --- a/apioforum/templates/view_post.html +++ b/apioforum/templates/view_post.html @@ -6,7 +6,7 @@ {% if not revision %} viewing post #{{post.id}} {% else %} - viewing revision #{{revision.id}} of #{{post.id}} + viewing revision #{{revision.rev_index}} of #{{post.id}} {% endif %} {%endblock%} </h1> @@ -24,18 +24,21 @@ <h2 id="history">revision history</h2> <table class="history"> {% for rev in history %} +{% set is_current = (not revision and loop.index==1) or (rev.rev_index == revision.rev_index) %} + <tr> - <td>{{disp_user(rev.editor)}} <td> - {% if rev.rev_index == revision.rev_index or (loop.index == 1 and not revision) %} - <b>{{ts(rev.time)}} ago</b> + {% if is_current %} + #{{post.id}}/{{rev.rev_index}} {% else %} <a href="{{url_for('thread.view_post', - post_id=post.id,revision=rev.rev_index if loop.index!=1 else None, - _anchor='history')}}"> - {{ts(rev.time)}} ago - </a> + post_id=post.id, revision=rev.rev_index if loop.index!=1 else None, + _anchor=None)}}"> + #{{post.id}}/{{rev.rev_index}}</a> {% endif %} + </td> + <td>{{disp_user(rev.editor)}} + <td>{{ts(rev.time)}}</td> {% if rev.comment %}<td>{{rev.comment}}</td>{%endif%} {% endfor %} </table> diff --git a/apioforum/thread.py b/apioforum/thread.py index 26e89e9..0db693f 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -422,35 +422,35 @@ def view_post(post_id): rev = None if 'revision' in request.args: - rev_idx = None + rev_index = None try: - rev_idx = int(request.args['revision']) + rev_index = int(request.args['revision']) except ValueError: abort(404) if not can_view_history: abort(403) rev = db.execute( "SELECT * FROM past_revisions WHERE post=? and rev_index=?;", - (post_id,rev_idx)).fetchone() + (post_id,rev_index)).fetchone() if not rev: abort(404) post = dict(post) post['content'] = rev['content'] post['updated'] = rev['time'] + post['rev_index'] = rev['rev_index'] history = None if can_view_history: history = db.execute(""" - SELECT editor, time, comment, rev_index FROM past_revisions WHERE post = ? ORDER BY rev_index 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 + history.insert(0, db.execute("""SELECT coalesce(editor,author) as editor, coalesce(updated, created) as "time [timestamp]", - comment, NULL as rev_index + comment, rev_index FROM posts WHERE id=?""",(post_id,)).fetchone()) - return render_template("view_post.html",post=post,revision=rev,history=history) def apply_selected_tags(thread, form): |
