Commit 70b0b5be by Kevin Chugh

update models

parent 4139f702
......@@ -10,7 +10,7 @@ urlpatterns = patterns('django_comment_client.base.views',
url(r'threads/(?P<thread_id>[\w\-]+)/reply$', 'create_comment', name='create_comment'),
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\-]+)/flagAbuse$', 'flag_abuse_for_thread', name='flag_abuse_for_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/unFlagAbuse$', 'un_flag_abuse_for_thread', name='un_flag_abuse_for_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/downvote$', 'vote_for_thread', name='downvote_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/unvote$', 'undo_vote_for_thread', name='undo_vote_for_thread'),
......
......@@ -238,28 +238,28 @@ def vote_for_thread(request, course_id, thread_id, value):
@require_POST
@login_required
@permitted
def flag_abuse_for_thread(request, course_id, thread_id, value):
def flag_abuse_for_thread(request, course_id, thread_id):
user = cc.User.from_django_user(request.user)
thread = cc.Thread.find(thread_id)
thread.flagAbuse(user,thread, value)
thread.flagAbuse(user,thread)
return JsonResponse(utils.safe_content(thread.to_dict()))
def un_flag_abuse_for_thread(request, course_id, thread_id, value):
def un_flag_abuse_for_thread(request, course_id, thread_id):
user = cc.User.from_django_user(request.user)
thread = cc.Thread.find(thread_id)
thread.unFlagAbuse(user,thread, value)
thread.unFlagAbuse(user,thread)
return JsonResponse(utils.safe_content(thread.to_dict()))
def flag_abuse_for_comment(request, course_id, comment_id, value):
def flag_abuse_for_comment(request, course_id, comment_id):
user = cc.User.from_django_user(request.user)
comment = cc.Comment.find(thread_id)
comment.flagAbuse(user,comment, value)
comment.flagAbuse(user,comment)
return JsonResponse(utils.safe_content(comment.to_dict()))
def un_flag_abuse_for_comment(request, course_id, comment_id, value):
def un_flag_abuse_for_comment(request, course_id, comment_id):
user = cc.User.from_django_user(request.user)
comment = cc.Comment.find(thread_id)
comment.unFlagAbuse(user,comment, value)
comment.unFlagAbuse(user,comment)
return JsonResponse(utils.safe_content(comment.to_dict()))
@require_POST
......
......@@ -72,8 +72,14 @@ class Thread(models.Model):
'mark_as_read': kwargs.get('mark_as_read', True),
}
def flagAbuse(self, user, voteable, value):
# user_id may be none, in which case it shouldn't be part of the
# request.
request_params = strip_none(request_params)
response = perform_request('get', url, request_params)
self.update_attributes(**response)
def flagAbuse(self, user, voteable):
if voteable.type == 'thread':
url = _url_for_flag_abuse_thread(voteable.id)
elif voteable.type == 'comment':
......@@ -84,7 +90,7 @@ class Thread(models.Model):
request = perform_request('put', url, params)
voteable.update_attributes(request)
def unFlagAbuse(self, user, voteable, value):
def unFlagAbuse(self, user, voteable):
if voteable.type == 'thread':
url = _url_for_unflag_abuse_thread(voteable.id)
elif voteable.type == 'comment':
......
......@@ -72,7 +72,7 @@ if Backbone?
toggleFollowing: (event) ->
$elem = $(event.target)
url = nullunFlagAbuse: ->
url = nullunFollow: ->
url = @model.urlFor("unFlagAbuse")
DiscussionUtil.safeAjax
$elem: @$(".discussion-flag-abuse")
......
......@@ -44,7 +44,7 @@
</header>
<div class="post-body">${'<%- body %>'}</div>
POST
<div class="discussion-flag-abuse notflagged" data-role="thread-flag" data-tooltip="flag">
<i class="icon"></i><span class="flag-label">Report Misuse</span></div>
......@@ -111,7 +111,7 @@
<p class="posted-details" title="${'<%- created_at %>'}">${'<%- created_at %>'}</p>
</header>
<div class="response-local"><div class="response-body">${"<%- body %>"}</div>
RESPONSE
<div class="discussion-flag-abuse notflagged" data-role="thread-flag" data-tooltip="flag">
<i class="icon"></i><span class="flag-label">Report Misuse</span></div>
</div>
......@@ -137,6 +137,7 @@
<script type="text/template" id="response-comment-show-template">
<div id="comment_${'<%- id %>'}">
<div class="response-body">${'<%- body %>'}</div>
COMMENT
<div class="discussion-flag-abuse notflagged" data-role="thread-flag" data-tooltip="flag">
<i class="icon"></i><span class="flag-label">Report Misuse</span></div>
<p class="posted-details">&ndash;posted <span class="timeago" title="${'<%- created_at %>'}">${'<%- created_at %>'}</span> by
......
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