Skip to content

add request to comment context #95

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

Closed
wants to merge 10 commits into from
33 changes: 12 additions & 21 deletions fluent_comments/static/fluent_comments/js/ajaxcomments.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,17 @@

$.fn.ready(function()
{
var commentform = $('form.js-comments-form');
if( commentform.length > 0 )
{
// Detect last active input.
// Submit if return is hit, or any button other then preview is hit.
commentform.find(':input').focus(setActiveInput).mousedown(setActiveInput);
commentform.submit(onCommentFormSubmit);
}


// Bind events for threaded comment reply
if($.fn.on) {
// jQuery 1.7+
$('body').on('click', '.comment-reply-link', showThreadedReplyForm);
}
else {
$('.comment-reply-link').live('click', showThreadedReplyForm);
}
$('body').on('focus mousedown', 'form.js-comments-form :input', setActiveInput)
.on('submit', 'form.js-comments-form', onCommentFormSubmit)
.on('click', '.comment-reply-link', showThreadedReplyForm)
.on('click', '.comment-cancel-reply-link', cancelThreadedReplyForm);
$(document).on('insertNode', onLoad);

$('.comment-cancel-reply-link').click(cancelThreadedReplyForm);
onLoad();
});

function onLoad(){
var $all_forms = $('.js-comments-form');
$all_forms
.each(function(){
Expand Down Expand Up @@ -92,8 +82,7 @@
if( ! isNaN(id)) // e.g. #comments in URL
scrollToComment(id, 1000);
}
});

}

function setActiveInput()
{
Expand Down Expand Up @@ -166,9 +155,11 @@
var $a = $(this);
var comment_id = $a.attr('data-comment-id');
var $comment = $a.closest('.comment-item');
var data_object_id = $a.parents('.comments').attr('data-object-id');
var form_selector = '.js-comments-form[data-object-id="' + data_object_id + '"]';

removeThreadedPreview();
$('.js-comments-form').appendTo($comment);
$(form_selector).appendTo($comment);
$($comment.find('#id_parent')[0]).val(comment_id);
}

Expand Down
5 changes: 4 additions & 1 deletion fluent_comments/templatetags/fluent_comments_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ def get_template_name(self, *tag_args, **tag_kwargs):
return get_comment_template_name(comment=tag_args[0])

def get_context_data(self, parent_context, *tag_args, **tag_kwargs):
return get_comment_context_data(comment=tag_args[0])
request = None
if hasattr(parent_context, 'get'):
request = parent_context.get('request', None)
return get_comment_context_data(comment=tag_args[0], request=request)


@register.tag
Expand Down
3 changes: 2 additions & 1 deletion fluent_comments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ def get_comment_template_name(comment):
]


def get_comment_context_data(comment, action=None):
def get_comment_context_data(comment, action=None, request=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that get_comment_context_data is called in 3 places, and each one should include the request.

"""
Internal function for the rendering of comments.
"""
return {
'comment': comment,
'action': action,
'preview': (action == 'preview'),
'request': request,
'USE_THREADEDCOMMENTS': appsettings.USE_THREADEDCOMMENTS,
}

Expand Down
2 changes: 1 addition & 1 deletion fluent_comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _ajax_result(request, form, action, comment=None, object_id=None):

if comment is not None:
# Render the comment, like {% render_comment comment %} does
context = get_comment_context_data(comment, action)
context = get_comment_context_data(comment, action, request)
template_name = get_comment_template_name(comment)
comment_html = render_to_string(template_name, context)

Expand Down