diff --git a/isso/db/comments.py b/isso/db/comments.py index 62cfad2..a66c248 100644 --- a/isso/db/comments.py +++ b/isso/db/comments.py @@ -110,7 +110,7 @@ class Comments: return dict(comment_count) def fetchall(self, mode=5, after=0, parent='any', order_by='id', - limit=100, page=0): + limit=100, page=0, asc=1): """ Return comments for admin with :param:`mode`. """ @@ -138,10 +138,16 @@ class Comments: # custom sanitization if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes', 'tid']: - order_by = 'id' - sql.append('ORDER BY ') - sql.append('comments.' + order_by + ", comments.created") - sql.append(' DESC') + sql.append('ORDER BY ') + sql.append("comments.created") + if not asc: + sql.append(' DESC') + else: + sql.append('ORDER BY ') + sql.append('comments.' + order_by) + if not asc: + sql.append(' DESC') + sql.append(", comments.created") if limit: sql.append('LIMIT ?,?') diff --git a/isso/templates/admin.html b/isso/templates/admin.html index 9d10816..376aa59 100644 --- a/isso/templates/admin.html +++ b/isso/templates/admin.html @@ -61,17 +61,17 @@ function delete_com(com_id, hash) {
+
+ Order: + {% for order in ['id', 'created', 'modified', 'likes', 'dislikes'] %} + + + {{ order }} + {% if order == order_by %} + {% if asc %} โ†‘ {% else %} โ†“ {% endif %} + {% else %} + โ†“ + {% endif %} + + + {% endfor %} +
{% set thread_id = "no_id" %} diff --git a/isso/views/comments.py b/isso/views/comments.py index 7dfd423..9621d7d 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -520,11 +520,13 @@ class API(object): return render_template('login.html') page_size = 100 page = int(req.args.get('page', 0)) - order_by = req.args.get('order_by', "id") + order_by = req.args.get('order_by', None) + asc = int(req.args.get('asc', 1)) mode = int(req.args.get('mode', 2)) comments = self.comments.fetchall(mode=mode, page=page, limit=page_size, - order_by=order_by) + order_by=order_by, + asc=asc) comments_enriched = [] for comment in list(comments): comment['hash'] = self.isso.sign(comment['id']) @@ -535,4 +537,4 @@ class API(object): page=int(page), mode=int(mode), conf=self.conf, max_page=max_page, counts=comment_mode_count, - order_by=order_by) + order_by=order_by, asc=asc)