def vote_for_comment(request, course_id, comment_id, value): """ Given a course_id and comment_id, vote for this response. AJAX only. """ comment = cc.Comment.find(comment_id) result = _vote_or_unvote(request, course_id, comment, value) comment_voted.send(sender=None, user=request.user, post=comment) course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) # Feature Flag to check that notifications are enabled or not. if value == 'up' and settings.FEATURES.get("ENABLE_NOTIFICATIONS", False): action_user_id = request.user.id original_poster_id = int(comment.user_id) thread = cc.Thread.find(comment.thread_id) # refetch the comment, so we have the updated counters comment = cc.Comment.find(comment_id) # we have to only send the notifications when # the user voting comment the comment is not # the same user who created the comment if action_user_id != original_poster_id: _send_discussion_notification( 'open-edx.lms.discussions.comment-upvoted', unicode(course_key), thread, request.user, recipient_user_id=original_poster_id, extra_payload={ 'num_upvotes': comment.votes['up_count'], }) return result
def vote_for_comment(request, course_id, comment_id, value): """ Given a course_id and comment_id, vote for this response. AJAX only. """ comment = cc.Comment.find(comment_id) result = _vote_or_unvote(request, course_id, comment, value) comment_voted.send(sender=None, user=request.user, post=comment) return result
def vote_for_comment(request, course_id, comment_id, value): """ given a course_id and comment_id, """ course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) user = request.user cc_user = cc.User.from_django_user(user) comment = cc.Comment.find(comment_id) cc_user.vote(comment, value) comment_voted.send(sender=None, user=user, post=comment) return JsonResponse(prepare_content(comment.to_dict(), course_key))
def vote_for_comment(request, course_id, comment_id, value): """ Given a course_id and comment_id, vote for this response. AJAX only. """ comment = cc.Comment.find(comment_id) result = _vote_or_unvote(request, course_id, comment, value) comment_voted.send(sender=None, user=request.user, post=comment) course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) # Feature Flag to check that notifications are enabled or not. if value == 'up' and settings.FEATURES.get("ENABLE_NOTIFICATIONS", False): action_user_id = request.user.id original_poster_id = int(comment.user_id) thread = cc.Thread.find(comment.thread_id) # refetch the comment, so we have the updated counters comment = cc.Comment.find(comment_id) # we have to only send the notifications when # the user voting comment the comment is not # the same user who created the comment if action_user_id != original_poster_id: _send_discussion_notification( 'open-edx.lms.discussions.comment-upvoted', unicode(course_key), thread, request.user, recipient_user_id=original_poster_id, extra_payload={ 'num_upvotes': comment.votes['up_count'], } ) return result