From 7d9d790c5d6bf95b9e62cbd43b9d389ab256000e Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Wed, 1 Aug 2012 12:43:57 -0400 Subject: [PATCH] endorse comments --- lms/djangoapps/django_comment_client/base/views.py | 8 ++++++-- lms/djangoapps/django_comment_client/forum/views.py | 2 ++ lms/static/coffee/src/discussion.coffee | 12 ++++++++++++ lms/static/sass/_discussion.scss | 6 ++++++ lms/templates/discussion/thread.html | 12 ++++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index f995829b79..ef86fb3b19 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -38,7 +38,12 @@ def comment_author_only(fn): return verified_fn def instructor_only(fn): #TODO add instructor verification - return fn + def verified_fn(request, *args, **kwargs): + if not request.user.is_staff: + return JsonError("unauthorized") + else: + return fn(request, *args, **kwargs) + return verified_fn def extract(dic, keys): return {k: dic[k] for k in keys} @@ -70,7 +75,6 @@ def create_comment(request, course_id, thread_id): attributes = extract(request.POST, ['body']) attributes['user_id'] = request.user.id attributes['course_id'] = course_id - print request.POST if request.POST.get('anonymous', 'false').lower() == 'true': attributes['anonymous'] = True if request.POST.get('autowatch', 'false').lower() == 'true': diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index b980db3963..a8608e0dad 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -38,6 +38,7 @@ def render_discussion(request, course_id, threads, discussion_id=None, with_sear 'user_info': comment_client.get_user_info(request.user.id, raw=True), 'tags': comment_client.get_threads_tags(raw=True), 'course_id': course_id, + 'request': request, } return render_to_string('discussion/inline.html', context) @@ -97,6 +98,7 @@ def render_single_thread(request, course_id, thread_id): 'annotated_content_info': json.dumps(get_annotated_content_info(thread=thread, user_id=request.user.id)), 'tags': comment_client.get_threads_tags(raw=True), 'course_id': course_id, + 'request': request, } return render_to_string('discussion/single_thread.html', context) diff --git a/lms/static/coffee/src/discussion.coffee b/lms/static/coffee/src/discussion.coffee index f7cece2e6a..cbb31fa3af 100644 --- a/lms/static/coffee/src/discussion.coffee +++ b/lms/static/coffee/src/discussion.coffee @@ -373,6 +373,15 @@ Discussion = Discussion.handleAnchorAndReload(response) , 'json' + handleEndorse = (elem) -> + url = Discussion.urlFor('endorse_comment', id) + endorsed = $local(".discussion-endorse").is(":checked") + $.post url, {endorsed: endorsed}, (response, textStatus) -> + # TODO error handling + Discussion.handleAnchorAndReload(response) + , 'json' + + $local(".discussion-reply").click -> handleReply(this) @@ -385,6 +394,9 @@ Discussion = $local(".discussion-vote-down").click -> handleVote(this, "down") + $local(".discussion-endorse").click -> + handleEndorse(this) + $local(".discussion-edit").click -> if $content.hasClass("thread") handleEditThread(this) diff --git a/lms/static/sass/_discussion.scss b/lms/static/sass/_discussion.scss index 030c32bf92..adefe34683 100644 --- a/lms/static/sass/_discussion.scss +++ b/lms/static/sass/_discussion.scss @@ -267,6 +267,12 @@ $discussion_input_width: 90%; display: block; color: black; } + + &.endorsed { + > .discussion-content { + background-color: lightyellow; + } + } } .discussion-votes { margin-right: 6px; diff --git a/lms/templates/discussion/thread.html b/lms/templates/discussion/thread.html index e49d555d59..5896927b44 100644 --- a/lms/templates/discussion/thread.html +++ b/lms/templates/discussion/thread.html @@ -15,7 +15,11 @@ <%def name="render_comments(comments)">
% for comment in comments: + % if comment['endorsed']: +
+ % else:
+ % endif ${render_content(comment, "comment")}
${render_comments(comment['children'])} @@ -76,6 +80,14 @@ % if type == "thread" and kwargs['edit_thread'] or type == "comment": ${render_link("discussion-link discussion-reply", "Reply")} ${render_link("discussion-link discussion-edit", "Edit")} + % if type == "comment" and request.user.is_staff: + % if content['endorsed']: + + % else: + + % endif + + % endif % endif