diff --git a/README.rst b/README.rst index e6cdbf7..b3ba345 100644 --- a/README.rst +++ b/README.rst @@ -172,6 +172,24 @@ The templates and admin interface adapt themselves automatically to show the threaded comments. +Javascript Controls +------------------- + +You are able to control various output settings via javascript. + +1. is_reversed: Will use prepend instead of append to insert the ajax created comment + + +Insert the following code, that does not wait for document.ready + +``` + +``` + Contributing ------------ diff --git a/fluent_comments/admin.py b/fluent_comments/admin.py index 9460d5d..547f667 100644 --- a/fluent_comments/admin.py +++ b/fluent_comments/admin.py @@ -55,8 +55,11 @@ class FluentCommentsAdmin(CommentsAdminBase): def object_link(self, comment): object = comment.content_object - title = unicode(object) - return u'{1}'.format(escape(object.get_absolute_url()), escape(title)) + if object is not None and hasattr(object, 'get_absolute_url'): + title = unicode(object) + return u'{1}'.format(escape(object.get_absolute_url()), escape(title)) + else: + return u'{1}'.format('#', 'Comment Content_Object does not exist') object_link.short_description = _("Page") object_link.allow_tags = True diff --git a/fluent_comments/models.py b/fluent_comments/models.py index 38fad31..95c19e4 100644 --- a/fluent_comments/models.py +++ b/fluent_comments/models.py @@ -34,8 +34,8 @@ def on_comment_posted(sender, comment, request, **kwargs): 'content_object': content_object } - message = render(request, "comments/comment_notification_email.txt", context) - send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list, fail_silently=True) + message = unicode(render(request, "comments/comment_notification_email.txt", context)) + send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list, fail_silently=False) def get_comments_for_model(content_object, include_moderated=False): diff --git a/fluent_comments/static/fluent_comments/js/ajaxcomments.js b/fluent_comments/static/fluent_comments/js/ajaxcomments.js index 12def5a..f9e1e56 100644 --- a/fluent_comments/static/fluent_comments/js/ajaxcomments.js +++ b/fluent_comments/static/fluent_comments/js/ajaxcomments.js @@ -7,9 +7,14 @@ var COMMENT_SCROLL_TOP_OFFSET = 40; var PREVIEW_SCROLL_TOP_OFFSET = 20; - $.fn.ready(function() { + + var COMMENT_CONTROLS = (window.COMMENT_CONTROLS !== undefined) ? window.COMMENT_CONTROLS : { + 'is_reversed': false, + 'scroll_to_comment': true, + }; + var commentform = $('form.js-comments-form'); if( commentform.length > 0 ) { @@ -93,7 +98,7 @@ function scrollToElement( $element, speed, offset ) { - if( $element.length ) + if( $element.length && COMMENT_CONTROLS.scroll_to_comment === true ) $(scrollElement).animate( {scrollTop: $element.offset().top - (offset || 0) }, speed || 1000 ); } @@ -222,22 +227,26 @@ function addComment(data) { // data contains the server-side response. - var html = data['html'] + var html = $(data['html']) // create the domElement and thus fire appropriate events var parent_id = data['parent_id']; var $new_comment; + + // define the action by which the comment is inserted at the top of the list or the bottom + var insert_action = (COMMENT_CONTROLS.is_reversed === true) ? 'prepend' : 'append' ; + if(parent_id) { var $parentLi = $("#c" + parseInt(parent_id)).parent('li.comment-wrapper'); var $commentUl = $parentLi.children('ul'); if( $commentUl.length == 0 ) $commentUl = $parentLi.append('