Skip to content

Support showing comments in reversed order #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand Down
2 changes: 2 additions & 0 deletions fluent_comments/appsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'")

Expand Down
14 changes: 11 additions & 3 deletions fluent_comments/static/fluent_comments/js/ajaxcomments.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@

function scrollToComment(id, speed)
{
if( ! ENABLE_COMMENT_SCROLL ) {
if( (! ENABLE_COMMENT_SCROLL) || data['order_reversed'] ) {
return;
}

Expand All @@ -133,7 +133,7 @@

function scrollToElement( $element, speed, offset )
{
if( ! ENABLE_COMMENT_SCROLL ) {
if( (! ENABLE_COMMENT_SCROLL) || data['order_reversed'] ) {
return;
}

Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@

{% endcomment %}
<div id="comments-{{ target_object_id }}" data-object-id="{{ target_object_id }}" class="comments {% if not comment_list %} empty{% endif %}">
{% 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 %}
</div>
2 changes: 2 additions & 0 deletions fluent_comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))

Expand Down