From 6f4400181316320694d59fa176adf60b3dc7ea0a Mon Sep 17 00:00:00 2001 From: Rocky Duan Date: Tue, 31 Jul 2012 10:11:51 -0400 Subject: [PATCH] basic editing functionality --- .../django_comment_client/base/views.py | 16 +- lms/djangoapps/django_comment_client/utils.py | 6 +- lms/static/coffee/src/customwmd.coffee | 4 +- lms/static/coffee/src/discussion.coffee | 139 ++++++++++++++---- lms/static/sass/_discussion.scss | 16 +- lms/templates/discussion/inline.html | 6 +- lms/templates/discussion/thread.html | 6 +- 7 files changed, 141 insertions(+), 52 deletions(-) diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index 86fe285af0..73cf4a4e27 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -19,24 +19,22 @@ from django_comment_client.utils import JsonResponse, JsonError def thread_author_only(fn): def verified_fn(request, *args, **kwargs): - thread_id = args.get('thread_id', False) or \ - kwargs.get('thread_id', False) + thread_id = kwargs.get('thread_id', False) thread = comment_client.get_thread(thread_id) - if request.user.id == thread['user_id']: + if str(request.user.id) == str(thread['user_id']): return fn(request, *args, **kwargs) else: - return JsonError(400, "unauthorized") + return JsonError("unauthorized") return verified_fn def comment_author_only(fn): def verified_fn(request, *args, **kwargs): - comment_id = args.get('comment_id', False) or \ - kwargs.get('comment_id', False) + comment_id = kwargs.get('comment_id', False) comment = comment_client.get_comment(comment_id) - if request.user.id == comment['user_id']: + if str(request.user.id) == str(comment['user_id']): return fn(request, *args, **kwargs) else: - return JsonError(400, "unauthorized") + return JsonError("unauthorized") return verified_fn def instructor_only(fn): #TODO add instructor verification @@ -81,7 +79,7 @@ def delete_thread(request, course_id, thread_id): response = comment_client.delete_thread(thread_id) return JsonResponse(response) -@thread_author_only +@comment_author_only @login_required @require_POST def update_comment(request, course_id, comment_id): diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index 30c74c0bb0..ef7ec4d4fc 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -100,8 +100,10 @@ class JsonResponse(HttpResponse): mimetype='application/json; charset=utf8') class JsonError(HttpResponse): - def __init__(self, error_message=""): - content = simplejson.dumps({'errors': error_message}, + def __init__(self, error_messages=[]): + if isinstance(error_messages, str): + error_messages = [error_messages] + content = simplejson.dumps({'errors': error_messages}, indent=2, ensure_ascii=False) super(JsonError, self).__init__(content, diff --git a/lms/static/coffee/src/customwmd.coffee b/lms/static/coffee/src/customwmd.coffee index bb22fcc7f2..4c8ee38f36 100644 --- a/lms/static/coffee/src/customwmd.coffee +++ b/lms/static/coffee/src/customwmd.coffee @@ -124,10 +124,12 @@ $ -> return if not $elem.find(".wmd-panel").length + initialText = $elem.html() + $elem.empty() _append = appended_id || "" $wmdPanel = $("
").addClass("wmd-panel") .append($("
").attr("id", "wmd-button-bar#{_append}")) - .append($("