convert flagging to one flag
This commit is contained in:
@@ -11,6 +11,7 @@ urlpatterns = patterns('django_comment_client.base.views',
|
||||
url(r'threads/(?P<thread_id>[\w\-]+)/delete', 'delete_thread', name='delete_thread'),
|
||||
url(r'threads/(?P<thread_id>[\w\-]+)/upvote$', 'vote_for_thread', {'value': 'up'}, name='upvote_thread'),
|
||||
url(r'threads/(?P<thread_id>[\w\-]+)/flagAbuse$', 'flag_abuse_for_thread', {'value': 'up'}, name='flag_abuse_for_thread'),
|
||||
url(r'threads/(?P<thread_id>[\w\-]+)/unFlagAbuse$', 'un_flag_abuse_for_thread', {'value': 'up'}, name='un_flag_abuse_for_thread'),
|
||||
url(r'threads/(?P<thread_id>[\w\-]+)/downvote$', 'vote_for_thread', {'value': 'down'}, name='downvote_thread'),
|
||||
url(r'threads/(?P<thread_id>[\w\-]+)/unvote$', 'undo_vote_for_thread', name='undo_vote_for_thread'),
|
||||
url(r'threads/(?P<thread_id>[\w\-]+)/follow$', 'follow_thread', name='follow_thread'),
|
||||
|
||||
@@ -244,6 +244,12 @@ def flag_abuse_for_thread(request, course_id, thread_id, value):
|
||||
thread.flagAbuse(user,thread, value)
|
||||
return JsonResponse(utils.safe_content(thread.to_dict()))
|
||||
|
||||
def un_flag_abuse_for_thread(request, course_id, thread_id, value):
|
||||
user = cc.User.from_django_user(request.user)
|
||||
thread = cc.Thread.find(thread_id)
|
||||
thread.unFlagAbuse(user,thread, value)
|
||||
return JsonResponse(utils.safe_content(thread.to_dict()))
|
||||
|
||||
@require_POST
|
||||
@login_required
|
||||
@permitted
|
||||
|
||||
@@ -352,7 +352,7 @@ def safe_content(content):
|
||||
'updated_at', 'depth', 'type', 'commentable_id', 'comments_count',
|
||||
'at_position_list', 'children', 'highlighted_title', 'highlighted_body',
|
||||
'courseware_title', 'courseware_url', 'tags', 'unread_comments_count',
|
||||
'read', "abuse_flaggers", "spoiler_flaggers"
|
||||
'read', "abuse_flaggers"
|
||||
]
|
||||
|
||||
if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False):
|
||||
|
||||
@@ -10,7 +10,7 @@ class Comment(models.Model):
|
||||
'id', 'body', 'anonymous', 'anonymous_to_peers', 'course_id',
|
||||
'endorsed', 'parent_id', 'thread_id', 'username', 'votes', 'user_id',
|
||||
'closed', 'created_at', 'updated_at', 'depth', 'at_position_list',
|
||||
'type', 'commentable_id', 'abuse_flaggers', 'spoiler_flaggers'
|
||||
'type', 'commentable_id', 'abuse_flaggers'
|
||||
]
|
||||
|
||||
updatable_fields = [
|
||||
|
||||
@@ -10,7 +10,7 @@ class Thread(models.Model):
|
||||
'closed', 'tags', 'votes', 'commentable_id', 'username', 'user_id',
|
||||
'created_at', 'updated_at', 'comments_count', 'unread_comments_count',
|
||||
'at_position_list', 'children', 'type', 'highlighted_title',
|
||||
'highlighted_body', 'endorsed', 'read', 'abuse_flaggers', 'spoiler_flaggers'
|
||||
'highlighted_body', 'endorsed', 'read', 'abuse_flaggers'
|
||||
]
|
||||
|
||||
updatable_fields = [
|
||||
@@ -74,6 +74,17 @@ class Thread(models.Model):
|
||||
|
||||
|
||||
def flagAbuse(self, user, voteable, value):
|
||||
if voteable.type == 'thread':
|
||||
url = _url_for_flag_abuse_thread(voteable.id)
|
||||
elif voteable.type == 'comment':
|
||||
url = _url_for_vote_comment(voteable.id)
|
||||
else:
|
||||
raise CommentClientError("Can only vote / unvote for threads or comments")
|
||||
params = {'user_id': user.id, 'value': value}
|
||||
request = perform_request('put', url, params)
|
||||
voteable.update_attributes(request)
|
||||
|
||||
def unFlagAbuse(self, user, voteable, value):
|
||||
if voteable.type == 'thread':
|
||||
url = _url_for_flag_abuse_thread(voteable.id)
|
||||
elif voteable.type == 'comment':
|
||||
|
||||
@@ -82,17 +82,18 @@ if Backbone?
|
||||
|
||||
class @Thread extends @Content
|
||||
urlMappers:
|
||||
'retrieve' : -> DiscussionUtil.urlFor('retrieve_single_thread', @discussion.id, @id)
|
||||
'reply' : -> DiscussionUtil.urlFor('create_comment', @id)
|
||||
'flagAbuse': -> DiscussionUtil.urlFor("flagAbuse_#{@get('type')}", @id)
|
||||
'unvote' : -> DiscussionUtil.urlFor("undo_vote_for_#{@get('type')}", @id)
|
||||
'upvote' : -> DiscussionUtil.urlFor("upvote_#{@get('type')}", @id)
|
||||
'downvote' : -> DiscussionUtil.urlFor("downvote_#{@get('type')}", @id)
|
||||
'close' : -> DiscussionUtil.urlFor('openclose_thread', @id)
|
||||
'update' : -> DiscussionUtil.urlFor('update_thread', @id)
|
||||
'delete' : -> DiscussionUtil.urlFor('delete_thread', @id)
|
||||
'follow' : -> DiscussionUtil.urlFor('follow_thread', @id)
|
||||
'unfollow' : -> DiscussionUtil.urlFor('unfollow_thread', @id)
|
||||
'retrieve' : -> DiscussionUtil.urlFor('retrieve_single_thread', @discussion.id, @id)
|
||||
'reply' : -> DiscussionUtil.urlFor('create_comment', @id)
|
||||
'flagAbuse' : -> DiscussionUtil.urlFor("flagAbuse_#{@get('type')}", @id)
|
||||
'unFlagAbuse' : -> DiscussionUtil.urlFor("unFlagAbuse_#{@get('type')}", @id)
|
||||
'unvote' : -> DiscussionUtil.urlFor("undo_vote_for_#{@get('type')}", @id)
|
||||
'upvote' : -> DiscussionUtil.urlFor("upvote_#{@get('type')}", @id)
|
||||
'downvote' : -> DiscussionUtil.urlFor("downvote_#{@get('type')}", @id)
|
||||
'close' : -> DiscussionUtil.urlFor('openclose_thread', @id)
|
||||
'update' : -> DiscussionUtil.urlFor('update_thread', @id)
|
||||
'delete' : -> DiscussionUtil.urlFor('delete_thread', @id)
|
||||
'follow' : -> DiscussionUtil.urlFor('follow_thread', @id)
|
||||
'unfollow' : -> DiscussionUtil.urlFor('unfollow_thread', @id)
|
||||
|
||||
initialize: ->
|
||||
@set('thread', @)
|
||||
@@ -120,7 +121,7 @@ if Backbone?
|
||||
@trigger "change", @
|
||||
|
||||
unflagAbuse: ->
|
||||
@get("votes")["up_count"] = parseInt(@get("votes")["up_count"]) - 1
|
||||
@get("abuse_flaggers").push window.user.get('id')
|
||||
@trigger "change", @
|
||||
|
||||
display_body: ->
|
||||
|
||||
@@ -49,6 +49,7 @@ class @DiscussionUtil
|
||||
create_comment : "/courses/#{$$course_id}/discussion/threads/#{param}/reply"
|
||||
delete_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/delete"
|
||||
flagAbuse_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/flagAbuse"
|
||||
unflagAbuse_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unFlagAbuse"
|
||||
upvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/upvote"
|
||||
downvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/downvote"
|
||||
undo_vote_for_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unvote"
|
||||
|
||||
@@ -4,7 +4,6 @@ if Backbone?
|
||||
events:
|
||||
"click .discussion-vote": "toggleVote"
|
||||
"click .discussion-flag-abuse": "toggleFlagAbuse"
|
||||
"click .discussion-flag-spoiler": "toggleFlagSpoiler"
|
||||
"click .action-follow": "toggleFollowing"
|
||||
"click .action-edit": "edit"
|
||||
"click .action-delete": "delete"
|
||||
@@ -26,6 +25,7 @@ if Backbone?
|
||||
@delegateEvents()
|
||||
@renderDogear()
|
||||
@renderVoted()
|
||||
@renderFlagged()
|
||||
@renderAttrs()
|
||||
@$("span.timeago").timeago()
|
||||
@convertMath()
|
||||
@@ -42,9 +42,18 @@ if Backbone?
|
||||
@$("[data-role=discussion-vote]").addClass("is-cast")
|
||||
else
|
||||
@$("[data-role=discussion-vote]").removeClass("is-cast")
|
||||
|
||||
renderFlagged: =>
|
||||
if window.user.id in @model.get("abuse_flaggers")
|
||||
@$("[thread-flag]").addClass("flagged")
|
||||
@$("[thread-flag]").removeClass("notflagged")
|
||||
else
|
||||
@$("[thread-flag]").removeClass("flagged")
|
||||
@$("[thread-flag]").addClass("notflagged")
|
||||
|
||||
updateModelDetails: =>
|
||||
@renderVoted()
|
||||
@renderFlagged()
|
||||
@$("[data-role=discussion-vote] .votes-count-number").html(@model.get("votes")["up_count"])
|
||||
|
||||
convertMath: ->
|
||||
@@ -60,20 +69,13 @@ if Backbone?
|
||||
@vote()
|
||||
|
||||
toggleFlagAbuse: (event) ->
|
||||
alert('flag')
|
||||
event.preventDefault()
|
||||
if window.user in @model.get("abuse_flaggers")
|
||||
@flagAbuse()
|
||||
else
|
||||
@unFlagAbuse()
|
||||
|
||||
toggleFlagSpoiler: (event) ->
|
||||
event.preventDefault()
|
||||
if window.user in @model.abuse_flaggers
|
||||
@unFlagAbuse()
|
||||
else
|
||||
@flagAbuse()
|
||||
|
||||
|
||||
toggleFollowing: (event) ->
|
||||
$elem = $(event.target)
|
||||
url = null
|
||||
@@ -100,6 +102,7 @@ if Backbone?
|
||||
@model.set(response, {silent: true})
|
||||
|
||||
flagAbuse: ->
|
||||
alert('flag abuse')
|
||||
url = @model.urlFor("flagAbuse")
|
||||
DiscussionUtil.safeAjax
|
||||
$elem: @$(".discussion-flag-abuse")
|
||||
@@ -121,10 +124,10 @@ if Backbone?
|
||||
@model.set(response, {silent: true})
|
||||
|
||||
unFlagAbuse: ->
|
||||
window.user.unvote(@model)
|
||||
url = @model.urlFor("unvote")
|
||||
alert('unflag abuse')
|
||||
url = @model.urlFor("unFlagAbuse")
|
||||
DiscussionUtil.safeAjax
|
||||
$elem: @$(".discussion-vote")
|
||||
$elem: @$(".discussion-flag-abuse")
|
||||
url: url
|
||||
type: "POST"
|
||||
success: (response, textStatus) =>
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
</header>
|
||||
|
||||
<div class="post-body">${'<%- body %>'}</div>
|
||||
<a href="#" class="discussion-flag-abuse notflagged" data-role="thread-flag" data-tooltip="flag">
|
||||
<a href="#" class="discussion-flag-abuse <% if user in abuse_flaggers %>flagged <%else%> notflagged<%end%> " data-role="thread-flag" data-tooltip="flag">
|
||||
<i class="icon"></i>Report Misuse</a>
|
||||
${'<% if (obj.courseware_url) { %>'}
|
||||
<div class="post-context">
|
||||
|
||||
Reference in New Issue
Block a user