From e301be4a808a48e409e19d8b699fa2511e2db083 Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Tue, 31 Jul 2012 11:54:02 -0400 Subject: [PATCH 1/2] modify anonymity handling; display comments count --- .../django_comment_client/base/views.py | 22 +++++++++++++------ lms/templates/discussion/thread.html | 10 +++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index 73cf4a4e27..f995829b79 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -49,6 +49,10 @@ def create_thread(request, course_id, commentable_id): attributes = extract(request.POST, ['body', 'title', 'tags']) attributes['user_id'] = request.user.id attributes['course_id'] = course_id + if request.POST.get('anonymous', 'false').lower() == 'true': + attributes['anonymous'] = True + if request.POST.get('autowatch', 'false').lower() == 'true': + attributes['auto_subscribe'] = True response = comment_client.create_thread(commentable_id, attributes) return JsonResponse(response) @@ -64,11 +68,13 @@ def update_thread(request, course_id, thread_id): @require_POST def create_comment(request, course_id, thread_id): attributes = extract(request.POST, ['body']) - if request.POST.get('anonymous', 'false').lower() == 'false': - attributes['user_id'] = request.user.id + attributes['user_id'] = request.user.id attributes['course_id'] = course_id - attributes['auto_subscribe'] = bool(request.POST.get('autowatch', False)) - print attributes + print request.POST + if request.POST.get('anonymous', 'false').lower() == 'true': + attributes['anonymous'] = True + if request.POST.get('autowatch', 'false').lower() == 'true': + attributes['auto_subscribe'] = True response = comment_client.create_comment(thread_id, attributes) return JsonResponse(response) @@ -99,10 +105,12 @@ def endorse_comment(request, course_id, comment_id): @require_POST def create_sub_comment(request, course_id, comment_id): attributes = extract(request.POST, ['body']) - if request.POST.get('anonymous', 'false').lower() == 'false': - attributes['user_id'] = request.user.id + attributes['user_id'] = request.user.id attributes['course_id'] = course_id - attributes['auto_subscribe'] = bool(request.POST.get('autowatch', False)) + if request.POST.get('anonymous', 'false').lower() == 'true': + attributes['anonymous'] = True + if request.POST.get('autowatch', 'false').lower() == 'true': + attributes['auto_subscribe'] = True response = comment_client.create_sub_comment(comment_id, attributes) return JsonResponse(response) diff --git a/lms/templates/discussion/thread.html b/lms/templates/discussion/thread.html index b0ece28643..deefd6284b 100644 --- a/lms/templates/discussion/thread.html +++ b/lms/templates/discussion/thread.html @@ -4,7 +4,6 @@ <%! import urllib %> <%def name="render_thread(course_id, thread, edit_thread=False, show_comments=False)"> -
${render_content(thread, "thread", edit_thread=edit_thread, show_comments=show_comments)} % if show_comments: @@ -83,10 +82,13 @@ <%def name="render_info(content)"> ${time_ago_in_words(parse(content['updated_at']))} ago by - % if content.get('user_id', False): - user No.${content['user_id']} - % else: + % if content['anonymous']: anonymous + % else: + user No.${content['user_id']} + % endif + % if content.get('comments_count', -1) >= 0: + / ${content['comments_count']} comment(s) % endif From 701f8716f75dfba06cf89068179f33eaad748b6c Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Tue, 31 Jul 2012 12:31:59 -0400 Subject: [PATCH 2/2] only show edit button when user can edit --- .../django_comment_client/forum/views.py | 16 +++++++++++++++- lms/static/coffee/src/discussion.coffee | 7 ++++++- lms/templates/discussion/single_thread.html | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 0a94603267..d878d55238 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -78,9 +78,23 @@ def forum_form_discussion(request, course_id, discussion_id): def render_single_thread(request, course_id, thread_id): + def get_annotated_content_info(thread, user_id): + infos = {} + def _annotate(content): + infos[str(content['id'])] = { + 'editable': str(content['user_id']) == str(user_id), # TODO may relax this to instructors + } + for child in content['children']: + _annotate(child) + _annotate(thread) + return infos + + thread = comment_client.get_thread(thread_id, recursive=True) + context = { - 'thread': comment_client.get_thread(thread_id, recursive=True), + 'thread': thread, 'user_info': comment_client.get_user_info(request.user.id, raw=True), + '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, } diff --git a/lms/static/coffee/src/discussion.coffee b/lms/static/coffee/src/discussion.coffee index 479c8f69dc..f655d020a4 100644 --- a/lms/static/coffee/src/discussion.coffee +++ b/lms/static/coffee/src/discussion.coffee @@ -197,7 +197,7 @@ Discussion = else view = { id: id - showWatchCheckbox: $discussionContent.parent(".thread").attr("_id") not in $$user_info.subscribed_thread_ids + showWatchCheckbox: $discussionContent.parents(".thread").attr("_id") not in $$user_info.subscribed_thread_ids } $discussionContent.append Mustache.render Discussion.replyTemplate, view Markdown.makeWmdEditor $local(".reply-body"), "-reply-body-#{id}", Discussion.urlFor('upload') @@ -339,6 +339,11 @@ Discussion = raw_text = $local(".content-body").html() converter = Markdown.getMathCompatibleConverter() $local(".content-body").html(converter.makeHtml(raw_text)) + id = $content.attr("_id") + if not ($$annotated_content_info[id] || [])['editable'] + $local(".discussion-edit").remove() + + bindDiscussionEvents: (discussion) -> $discussion = $(discussion) diff --git a/lms/templates/discussion/single_thread.html b/lms/templates/discussion/single_thread.html index a3d57b867c..7157bd2296 100644 --- a/lms/templates/discussion/single_thread.html +++ b/lms/templates/discussion/single_thread.html @@ -14,4 +14,5 @@ var $$user_info = JSON.parse('${user_info | escape_quotes}'); var $$course_id = "${course_id}"; var $$tags = JSON.parse("${tags | escape_quotes}"); + var $$annotated_content_info = JSON.parse("${annotated_content_info | escape_quotes}");