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

Conversation

rodolphopivetta
Copy link

In my case I needed the request context to check if the user was authenticated to show or not the "reply" link.

@codecov
Copy link

codecov bot commented May 30, 2017

Codecov Report

Merging #95 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #95      +/-   ##
=========================================
+ Coverage   85.03%   85.1%   +0.07%     
=========================================
  Files          16      16              
  Lines         608     611       +3     
=========================================
+ Hits          517     520       +3     
  Misses         91      91
Impacted Files Coverage Δ
fluent_comments/views.py 84.14% <100%> (ø) ⬆️
fluent_comments/utils.py 96.42% <100%> (ø) ⬆️
...uent_comments/templatetags/fluent_comments_tags.py 90.54% <100%> (+0.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef455b2...b4b04a3. Read the comment docs.

@@ -145,7 +145,8 @@ 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, _ = parent_context
Copy link
Contributor

Choose a reason for hiding this comment

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

This can't possibly work on Python 2.
How about request = parent_context.get('request')

Copy link
Contributor

@vdboor vdboor left a comment

Choose a reason for hiding this comment

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

Hi!

Thanks for these changes. Although a lot more is included, they are useful changes. However, could you please look into these review comments?

@@ -23,7 +23,7 @@ class AjaxCommentTags(BaseInclusionNode):
Using the ``@register.inclusion_tag`` is not sufficient,
because some keywords require custom parsing.
"""
template_name = "fluent_comments/templatetags/ajax_comment_tags.html"
template_name = "comments/ajax_comment_tags.html"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the template changed?

Copy link
Author

Choose a reason for hiding this comment

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

to be able to override the template if needed

$('body').on('mousedown', 'form.js-comments-form :input', setActiveInput);
$('body').on('submit', 'form.js-comments-form', onCommentFormSubmit);
$('body').on('click', '.comment-reply-link', showThreadedReplyForm);
$('body').on('click', '.comment-cancel-reply-link', cancelThreadedReplyForm);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you make sure the $body is fetched only once?

@@ -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.

@rodolphopivetta
Copy link
Author

Thanks @vdboor, i'll add the changes tonight.

@vdboor
Copy link
Contributor

vdboor commented Aug 16, 2017

I'm sorry, I noticed that the JavaScript changes are too invasive. The onLoad is called one every insertNode, which could also reinitialize the comments for totally unrelated changes.

There have been several unfinished attempts to convert the script to a jQuery plugin format, which would make such re-initialization much easier too. That might be a good starting point implementing this change.

Instead, I've fixed the request value elsewhere in 82856c6

@vdboor vdboor closed this Aug 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants