From ee09df6b75cafa25e1b4b132abacecaf25e5be29 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sun, 21 Sep 2014 17:44:04 +0200 Subject: [PATCH] Support showing comments in reversed order --- README.rst | 11 +++++++++++ fluent_comments/appsettings.py | 2 ++ .../static/fluent_comments/js/ajaxcomments.js | 14 +++++++++++--- .../fluent_comments/templatetags/flat_list.html | 6 +++++- fluent_comments/views.py | 2 ++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index d85482e..47e48be 100644 --- a/README.rst +++ b/README.rst @@ -173,6 +173,17 @@ It can be enabled using the following settings:: The templates and admin interface adapt themselves automatically to show the threaded comments. +Other settings +-------------- + +For reversing the order of the comments (new comments are appended +at the top of the list, rather than at the end), use the following +option. + + FLUENT_COMMENTS_ORDER_REVERSED = True + +Currently, this supports only simple comments (no threads). This also +blocks the scrolling for newly posted comments. Contributing ------------ diff --git a/fluent_comments/appsettings.py b/fluent_comments/appsettings.py index 69b1cc7..da80740 100644 --- a/fluent_comments/appsettings.py +++ b/fluent_comments/appsettings.py @@ -19,6 +19,8 @@ FLUENT_COMMENTS_EXCLUDE_FIELDS = getattr(settings, 'FLUENT_COMMENTS_EXCLUDE_FIELDS', ()) or () +FLUENT_COMMENTS_ORDER_REVERSED = getattr(settings, 'FLUENT_COMMENTS_ORDER_REVERSED', False) + if FLUENT_COMMENTS_AKISMET_ACTION not in ('moderate', 'delete'): raise ImproperlyConfigured("FLUENT_COMMENTS_AKISMET_ACTION can be 'moderate' or 'delete'") diff --git a/fluent_comments/static/fluent_comments/js/ajaxcomments.js b/fluent_comments/static/fluent_comments/js/ajaxcomments.js index 5b727d4..804edc1 100644 --- a/fluent_comments/static/fluent_comments/js/ajaxcomments.js +++ b/fluent_comments/static/fluent_comments/js/ajaxcomments.js @@ -112,7 +112,7 @@ function scrollToComment(id, speed) { - if( ! ENABLE_COMMENT_SCROLL ) { + if( (! ENABLE_COMMENT_SCROLL) || data['order_reversed'] ) { return; } @@ -133,7 +133,7 @@ function scrollToElement( $element, speed, offset ) { - if( ! ENABLE_COMMENT_SCROLL ) { + if( (! ENABLE_COMMENT_SCROLL) || data['order_reversed'] ) { return; } @@ -287,7 +287,15 @@ { // data contains the server-side response. var $newCommentTarget = addCommentWrapper(data, '') - $newCommentTarget.append(data['html']).removeClass('empty'); + + // prepend or append the comment depending on the settings + if (data['order_reversed']) { + $newCommentTarget.prepend(data['html']).removeClass('empty'); + } + else { + $newCommentTarget.append(data['html']).removeClass('empty'); + } + return $("#c" + parseInt(data.comment_id)); } diff --git a/fluent_comments/templates/fluent_comments/templatetags/flat_list.html b/fluent_comments/templates/fluent_comments/templatetags/flat_list.html index ae8fd3b..551746e 100644 --- a/fluent_comments/templates/fluent_comments/templatetags/flat_list.html +++ b/fluent_comments/templates/fluent_comments/templatetags/flat_list.html @@ -8,5 +8,9 @@ {% endcomment %}
- {% for comment in comment_list %}{% include "comments/comment.html" %}{% endfor %} + {% if ORDER_REVERSED %} + {% for comment in comment_list reversed %}{% include "comments/comment.html" %}{% endfor %} + {% else %} + {% for comment in comment_list %}{% include "comments/comment.html" %}{% endfor %} + {% endif %}
diff --git a/fluent_comments/views.py b/fluent_comments/views.py index c78c29e..7564dbd 100644 --- a/fluent_comments/views.py +++ b/fluent_comments/views.py @@ -130,6 +130,7 @@ def _ajax_result(request, form, action, comment=None, object_id=None): 'errors': json_errors, 'object_id': object_id, 'use_threadedcomments': bool(appsettings.USE_THREADEDCOMMENTS), + 'order_reversed': bool(appsettings.FLUENT_COMMENTS_ORDER_REVERSED), } if comment is not None: @@ -138,6 +139,7 @@ def _ajax_result(request, form, action, comment=None, object_id=None): 'action': action, 'preview': (action == 'preview'), 'USE_THREADEDCOMMENTS': appsettings.USE_THREADEDCOMMENTS, + 'ORDER_REVERSED': appsettings.FLUENT_COMMENTS_ORDER_REVERSED, } comment_html = render_to_string('comments/comment.html', context, context_instance=RequestContext(request))