From 75c478771e3d114e1e373918df3cefb60fbbc5dd Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Wed, 1 Aug 2012 12:42:57 -0400 Subject: [PATCH 1/4] fixed histogram bug under staff view --- lms/djangoapps/courseware/module_render.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index cf61f2e101..02b476750f 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -184,7 +184,7 @@ def get_module(user, request, location, student_module_cache, position=None): ) if settings.MITX_FEATURES.get('DISPLAY_HISTOGRAMS_TO_STAFF') and user.is_staff: - module.get_html = add_histogram(module.get_html) + module.get_html = add_histogram(module.get_html, module) # If StudentModule for this instance wasn't already in the database, # and this isn't a guest user, create it. From 7d9d790c5d6bf95b9e62cbd43b9d389ab256000e Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Wed, 1 Aug 2012 12:43:57 -0400 Subject: [PATCH 2/4] 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
From 51772c04f31b52f3780b3f8d060b02de9e892b3c Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Wed, 1 Aug 2012 13:02:57 -0400 Subject: [PATCH 3/4] use separate templates for forum view and inline view --- .../django_comment_client/forum/views.py | 16 ++++++++---- lms/templates/discussion/forum.html | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 lms/templates/discussion/forum.html diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index a8608e0dad..5d54e95701 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -29,7 +29,7 @@ def render_accordion(request, course, discussion_id): return render_to_string('discussion/accordion.html', context) -def render_discussion(request, course_id, threads, discussion_id=None, with_search_bar=True, search_text=''): +def render_discussion(request, course_id, threads, discussion_id=None, with_search_bar=True, search_text='', template='discussion/inline.html'): context = { 'threads': threads, 'discussion_id': discussion_id, @@ -40,11 +40,17 @@ def render_discussion(request, course_id, threads, discussion_id=None, with_sear 'course_id': course_id, 'request': request, } - return render_to_string('discussion/inline.html', context) + return render_to_string(template, context) + +def render_inline_discussion(*args, **kwargs): + return render_discussion(template='discussion/inline.html', *args, **kwargs) + +def render_forum_discussion(*args, **kwargs): + return render_discussion(template='discussion/forum.html', *args, **kwargs) def inline_discussion(request, course_id, discussion_id): threads = comment_client.get_threads(discussion_id, recursive=False) - html = render_discussion(request, course_id, threads, discussion_id=discussion_id) + html = render_inline_discussion(request, course_id, threads, discussion_id=discussion_id) return HttpResponse(html, content_type="text/plain") def render_search_bar(request, course_id, discussion_id=None, text=''): @@ -71,7 +77,7 @@ def forum_form_discussion(request, course_id, discussion_id): context = { 'csrf': csrf(request)['csrf_token'], 'course': course, - 'content': render_discussion(request, course_id, threads, discussion_id=discussion_id, search_text=search_text), + 'content': render_forum_discussion(request, course_id, threads, discussion_id=discussion_id, search_text=search_text), 'accordion': render_accordion(request, course, discussion_id), } @@ -133,7 +139,7 @@ def search(request, course_id): context = { 'csrf': csrf(request)['csrf_token'], 'init': '', - 'content': render_discussion(request, course_id, threads, search_text=text), + 'content': render_forum_discussion(request, course_id, threads, search_text=text), 'accordion': '', 'course': course, } diff --git a/lms/templates/discussion/forum.html b/lms/templates/discussion/forum.html new file mode 100644 index 0000000000..074c956cbd --- /dev/null +++ b/lms/templates/discussion/forum.html @@ -0,0 +1,25 @@ +<%namespace name="renderer" file="thread.html"/> + +
+
+ + ${search_bar} +
New Post
+
+ % for thread in threads: + ${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)} + % endfor +
+ +<%! + def escape_quotes(text): + return text.replace('\"', '\\\"').replace("\'", "\\\'") +%> + + From f204e9888f9f9c6c7e396b5ce7d0a8000a6e1cb3 Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Wed, 1 Aug 2012 13:09:19 -0400 Subject: [PATCH 4/4] renamed files --- lms/djangoapps/django_comment_client/forum/views.py | 12 ++++++------ .../discussion/{accordion.html => _accordion.html} | 0 ..._show_discussion.html => _discussion_module.html} | 0 lms/templates/discussion/{forum.html => _forum.html} | 2 +- .../discussion/{inline.html => _inline.html} | 2 +- .../discussion/{search_bar.html => _search_bar.html} | 0 .../{single_thread.html => _single_thread.html} | 2 +- .../discussion/{thread.html => _thread.html} | 0 8 files changed, 9 insertions(+), 9 deletions(-) rename lms/templates/discussion/{accordion.html => _accordion.html} (100%) rename lms/templates/discussion/{_show_discussion.html => _discussion_module.html} (100%) rename lms/templates/discussion/{forum.html => _forum.html} (93%) rename lms/templates/discussion/{inline.html => _inline.html} (93%) rename lms/templates/discussion/{search_bar.html => _search_bar.html} (100%) rename lms/templates/discussion/{single_thread.html => _single_thread.html} (92%) rename lms/templates/discussion/{thread.html => _thread.html} (100%) diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 5d54e95701..16bee537d3 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -27,9 +27,9 @@ def render_accordion(request, course, discussion_id): 'csrf': csrf(request)['csrf_token'], } - return render_to_string('discussion/accordion.html', context) + return render_to_string('discussion/_accordion.html', context) -def render_discussion(request, course_id, threads, discussion_id=None, with_search_bar=True, search_text='', template='discussion/inline.html'): +def render_discussion(request, course_id, threads, discussion_id=None, with_search_bar=True, search_text='', template='discussion/_inline.html'): context = { 'threads': threads, 'discussion_id': discussion_id, @@ -43,10 +43,10 @@ def render_discussion(request, course_id, threads, discussion_id=None, with_sear return render_to_string(template, context) def render_inline_discussion(*args, **kwargs): - return render_discussion(template='discussion/inline.html', *args, **kwargs) + return render_discussion(template='discussion/_inline.html', *args, **kwargs) def render_forum_discussion(*args, **kwargs): - return render_discussion(template='discussion/forum.html', *args, **kwargs) + return render_discussion(template='discussion/_forum.html', *args, **kwargs) def inline_discussion(request, course_id, discussion_id): threads = comment_client.get_threads(discussion_id, recursive=False) @@ -61,7 +61,7 @@ def render_search_bar(request, course_id, discussion_id=None, text=''): 'text': text, 'course_id': course_id, } - return render_to_string('discussion/search_bar.html', context) + return render_to_string('discussion/_search_bar.html', context) def forum_form_discussion(request, course_id, discussion_id): @@ -106,7 +106,7 @@ def render_single_thread(request, course_id, thread_id): 'course_id': course_id, 'request': request, } - return render_to_string('discussion/single_thread.html', context) + return render_to_string('discussion/_single_thread.html', context) def single_thread(request, course_id, discussion_id, thread_id): diff --git a/lms/templates/discussion/accordion.html b/lms/templates/discussion/_accordion.html similarity index 100% rename from lms/templates/discussion/accordion.html rename to lms/templates/discussion/_accordion.html diff --git a/lms/templates/discussion/_show_discussion.html b/lms/templates/discussion/_discussion_module.html similarity index 100% rename from lms/templates/discussion/_show_discussion.html rename to lms/templates/discussion/_discussion_module.html diff --git a/lms/templates/discussion/forum.html b/lms/templates/discussion/_forum.html similarity index 93% rename from lms/templates/discussion/forum.html rename to lms/templates/discussion/_forum.html index 074c956cbd..967ebb9994 100644 --- a/lms/templates/discussion/forum.html +++ b/lms/templates/discussion/_forum.html @@ -1,4 +1,4 @@ -<%namespace name="renderer" file="thread.html"/> +<%namespace name="renderer" file="_thread.html"/>
diff --git a/lms/templates/discussion/inline.html b/lms/templates/discussion/_inline.html similarity index 93% rename from lms/templates/discussion/inline.html rename to lms/templates/discussion/_inline.html index 074c956cbd..967ebb9994 100644 --- a/lms/templates/discussion/inline.html +++ b/lms/templates/discussion/_inline.html @@ -1,4 +1,4 @@ -<%namespace name="renderer" file="thread.html"/> +<%namespace name="renderer" file="_thread.html"/>
diff --git a/lms/templates/discussion/search_bar.html b/lms/templates/discussion/_search_bar.html similarity index 100% rename from lms/templates/discussion/search_bar.html rename to lms/templates/discussion/_search_bar.html diff --git a/lms/templates/discussion/single_thread.html b/lms/templates/discussion/_single_thread.html similarity index 92% rename from lms/templates/discussion/single_thread.html rename to lms/templates/discussion/_single_thread.html index 7157bd2296..c66b39bfac 100644 --- a/lms/templates/discussion/single_thread.html +++ b/lms/templates/discussion/_single_thread.html @@ -1,4 +1,4 @@ -<%namespace name="renderer" file="thread.html"/> +<%namespace name="renderer" file="_thread.html"/>
Discussion diff --git a/lms/templates/discussion/thread.html b/lms/templates/discussion/_thread.html similarity index 100% rename from lms/templates/discussion/thread.html rename to lms/templates/discussion/_thread.html