endorse comments
This commit is contained in:
@@ -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':
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -267,6 +267,12 @@ $discussion_input_width: 90%;
|
||||
display: block;
|
||||
color: black;
|
||||
}
|
||||
|
||||
&.endorsed {
|
||||
> .discussion-content {
|
||||
background-color: lightyellow;
|
||||
}
|
||||
}
|
||||
}
|
||||
.discussion-votes {
|
||||
margin-right: 6px;
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
<%def name="render_comments(comments)">
|
||||
<div class="comments">
|
||||
% for comment in comments:
|
||||
% if comment['endorsed']:
|
||||
<div class="comment endorsed" _id="${comment['id']}">
|
||||
% else:
|
||||
<div class="comment" _id="${comment['id']}">
|
||||
% endif
|
||||
${render_content(comment, "comment")}
|
||||
<div class="comments">
|
||||
${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']:
|
||||
<input type="checkbox" checked="checked" class="discussion-link discussion-endorse" id="discussion-endorse-${content['id']}">
|
||||
% else:
|
||||
<input type="checkbox" class="discussion-link discussion-endorse" id="discussion-endorse-${content['id']}">
|
||||
% endif
|
||||
<label class="discussion-link" for="discussion-endorse-${content['id']}">Endorsed</label>
|
||||
% endif
|
||||
% endif
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
Reference in New Issue
Block a user