Commit 25568423 by Rocky Duan

fix reply & some random stuff

parent 5c457d70
......@@ -38,7 +38,7 @@ def comment_author_only(fn):
return JsonError("unauthorized")
return verified_fn
def instructor_only(fn): #TODO add instructor verification
def instructor_only(fn):
def verified_fn(request, *args, **kwargs):
if not request.user.is_staff:
return JsonError("unauthorized")
......@@ -46,8 +46,6 @@ def instructor_only(fn): #TODO add instructor verification
return fn(request, *args, **kwargs)
return verified_fn
@login_required
@require_POST
def create_thread(request, course_id, commentable_id):
......@@ -64,9 +62,10 @@ def create_thread(request, course_id, commentable_id):
'course_id': course_id,
'thread': response,
}
html = render_to_string('discussion/ajax_thread_only.html', context)
html = render_to_string('discussion/ajax_create_thread.html', context)
return JsonResponse({
'html': html,
'content': response,
})
else:
return JsonResponse(response)
......@@ -77,6 +76,15 @@ def create_thread(request, course_id, commentable_id):
def update_thread(request, course_id, thread_id):
attributes = extract(request.POST, ['body', 'title', 'tags'])
response = comment_client.update_thread(thread_id, attributes)
if response.is_ajax():
context = {
'thread': response,
}
html = render_to_string('discussion/ajax_update_thread.html', context)
return JsonResponse({
'html': html,
'content': response,
})
return JsonResponse(response)
def _create_comment(request, course_id, _response_from_attributes):
......@@ -92,9 +100,10 @@ def _create_comment(request, course_id, _response_from_attributes):
context = {
'comment': response,
}
html = render_to_string('discussion/ajax_comment_only.html', context)
html = render_to_string('discussion/ajax_create_comment.html', context)
return JsonResponse({
'html': html,
'content': response,
})
else:
return JsonResponse(response)
......@@ -119,6 +128,15 @@ def delete_thread(request, course_id, thread_id):
def update_comment(request, course_id, comment_id):
attributes = extract(request.POST, ['body'])
response = comment_client.update_comment(comment_id, attributes)
if response.is_ajax():
context = {
'comment': response,
}
html = render_to_string('discussion/ajax_update_comment.html', context)
return JsonResponse({
'html': html,
'content': response,
})
return JsonResponse(response)
@instructor_only
......
......@@ -19,7 +19,7 @@ import comment_client
import dateutil
THREADS_PER_PAGE = 20
THREADS_PER_PAGE = 5
PAGES_NEARBY_DELTA = 2
def render_accordion(request, course, discussion_id):
......
......@@ -25,9 +25,9 @@ Discussion = @Discussion
}
$discussionContent.append Mustache.render Discussion.replyTemplate, view
Discussion.makeWmdEditor $content, $local, "reply-body"
$local(".discussion-reply").hide()
$local(".discussion-submit-post").click -> handleSubmitReply(this)
$local(".discussion-cancel-post").click -> handleCancelReply(this)
$discussionContent.attr("status", "reply")
handleCancelReply = (elem) ->
$replyView = $local(".discussion-reply-new")
......@@ -35,7 +35,7 @@ Discussion = @Discussion
$replyView.hide()
#reply = Discussion.generateDiscussionLink("discussion-reply", "Reply", handleReply)
#$(elem).replaceWith(reply)
$discussionContent.attr("status", "normal")
$local(".discussion-reply").show()
handleSubmitReply = (elem) ->
if $content.hasClass("thread")
......@@ -63,10 +63,11 @@ Discussion = @Discussion
$comment = $(response.html)
$content.children(".comments").prepend($comment)
Discussion.setWmdContent $content, $local, "reply-body", ""
Discussion.setContentInfo id, 'editable', true
Discussion.setContentInfo response.content['id'], 'editable', true
Discussion.initializeContent($comment)
Discussion.bindContentEvents($comment)
$local(".discussion-reply-new").hide()
$local(".discussion-reply").show()
$discussionContent.attr("status", "normal")
)
......
......@@ -107,7 +107,7 @@ initializeFollowThread = (index, thread) ->
$thread = $(response.html)
$discussion.children(".threads").prepend($thread)
Discussion.setWmdContent $discussion, $local, "new-post-body", ""
Discussion.setContentInfo id, 'editable', true
Discussion.setContentInfo response.content['id'], 'editable', true
Discussion.initializeContent($thread)
Discussion.bindContentEvents($thread)
$(".new-post-form").hide()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment