From 0b6a0e4d5fc17be9280c80eef5f38c68c809ea5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Latinier?= Date: Sat, 16 Jul 2016 00:53:52 +0200 Subject: [PATCH] add: group by thread --- isso/css/admin.css | 7 +++++++ isso/db/comments.py | 4 ++-- isso/templates/admin.html | 13 +++++++++++++ isso/views/comments.py | 7 +++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/isso/css/admin.css b/isso/css/admin.css index d6a8f74..5a434fc 100644 --- a/isso/css/admin.css +++ b/isso/css/admin.css @@ -116,3 +116,10 @@ a { .isso-comment-footer a { cursor: pointer; } +.thread-title { + margin-left: 3em; +} +.group { + float: left; + margin-left: 2em; +} diff --git a/isso/db/comments.py b/isso/db/comments.py index 69790ac..62cfad2 100644 --- a/isso/db/comments.py +++ b/isso/db/comments.py @@ -137,10 +137,10 @@ class Comments: sql_args.append(parent) # custom sanitization - if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes']: + if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes', 'tid']: order_by = 'id' sql.append('ORDER BY ') - sql.append('comments.' + order_by) + sql.append('comments.' + order_by + ", comments.created") sql.append(' DESC') if limit: diff --git a/isso/templates/admin.html b/isso/templates/admin.html index c32ff1e..9d10816 100644 --- a/isso/templates/admin.html +++ b/isso/templates/admin.html @@ -77,6 +77,9 @@ function delete_com(com_id, hash) { +
+ Group by thread: +
+ {% set thread_id = "no_id" %} {% for comment in comments %} + {% if order_by == "tid" %} + {% if thread_id != comment.tid %} + {% set thread_id = comment.tid %} +

{{comment.title}}

+ {% endif %} + {% endif %}
{% if conf.avatar %}
@@ -103,6 +113,9 @@ function delete_com(com_id, hash) { {% endif %}
+ {% if order_by != "tid" %} + Thread: {{comment.title}}
+ {% endif %} {% if comment.author %} {{comment.author}} {% else %} diff --git a/isso/views/comments.py b/isso/views/comments.py index 68c228f..df1eebe 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -520,9 +520,11 @@ class API(object): return render_template('login.html') page_size = 100 page = req.args.get('page', 0) + order_by = req.args.get('order_by', "id") mode = req.args.get('mode', 2) comments = self.comments.fetchall(mode=mode, page=page, - limit=page_size) + limit=page_size, + order_by=order_by) comments_enriched = [] for comment in list(comments): comment['hash'] = self.isso.sign(comment['id']) @@ -532,4 +534,5 @@ class API(object): return render_template('admin.html', comments=comments_enriched, page=int(page), mode=int(mode), conf=self.conf, max_page=max_page, - counts=comment_mode_count) + counts=comment_mode_count, + order_by=order_by)