Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
600beb28
Commit
600beb28
authored
Aug 03, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ajax vote / unvote comments
parent
5d30c2de
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
12 deletions
+57
-12
lms/djangoapps/django_comment_client/base/urls.py
+2
-0
lms/djangoapps/django_comment_client/base/views.py
+14
-0
lms/lib/comment_client.py
+2
-4
lms/static/coffee/src/discussion/content.coffee
+35
-6
lms/static/coffee/src/discussion/discussion.coffee
+1
-1
lms/static/coffee/src/discussion/utils.coffee
+2
-0
lms/templates/discussion/_thread.html
+1
-1
No files found.
lms/djangoapps/django_comment_client/base/urls.py
View file @
600beb28
...
...
@@ -10,6 +10,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\-]+)/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'
),
url
(
r'threads/(?P<thread_id>[\w\-]+)/unfollow$'
,
'unfollow_thread'
,
name
=
'unfollow_thread'
),
...
...
@@ -19,6 +20,7 @@ urlpatterns = patterns('django_comment_client.base.views',
url
(
r'comments/(?P<comment_id>[\w\-]+)/delete$'
,
'delete_comment'
,
name
=
'delete_comment'
),
url
(
r'comments/(?P<comment_id>[\w\-]+)/upvote$'
,
'vote_for_comment'
,
{
'value'
:
'up'
},
name
=
'upvote_comment'
),
url
(
r'comments/(?P<comment_id>[\w\-]+)/downvote$'
,
'vote_for_comment'
,
{
'value'
:
'down'
},
name
=
'downvote_comment'
),
url
(
r'comments/(?P<comment_id>[\w\-]+)/unvote$'
,
'undo_vote_for_comment'
,
name
=
'undo_vote_for_comment'
),
url
(
r'(?P<commentable_id>[\w\-]+)/threads/create$'
,
'create_thread'
,
name
=
'create_thread'
),
url
(
r'(?P<commentable_id>[\w\-]+)/follow$'
,
'follow_commentable'
,
name
=
'follow_commentable'
),
...
...
lms/djangoapps/django_comment_client/base/views.py
View file @
600beb28
...
...
@@ -174,6 +174,13 @@ def vote_for_comment(request, course_id, comment_id, value):
@login_required
@require_POST
def
undo_vote_for_comment
(
request
,
course_id
,
comment_id
):
user_id
=
request
.
user
.
id
response
=
comment_client
.
undo_vote_for_comment
(
comment_id
,
user_id
)
return
JsonResponse
(
response
)
@login_required
@require_POST
def
vote_for_thread
(
request
,
course_id
,
thread_id
,
value
):
user_id
=
request
.
user
.
id
response
=
comment_client
.
vote_for_thread
(
thread_id
,
user_id
,
value
)
...
...
@@ -181,6 +188,13 @@ def vote_for_thread(request, course_id, thread_id, value):
@login_required
@require_POST
def
undo_vote_for_thread
(
request
,
course_id
,
thread_id
):
user_id
=
request
.
user
.
id
response
=
comment_client
.
undo_vote_for_thread
(
thread_id
,
user_id
)
return
JsonResponse
(
response
)
@login_required
@require_POST
def
follow_thread
(
request
,
course_id
,
thread_id
):
user_id
=
request
.
user
.
id
response
=
comment_client
.
subscribe_thread
(
user_id
,
thread_id
)
...
...
lms/lib/comment_client.py
View file @
600beb28
...
...
@@ -66,13 +66,13 @@ def vote_for_comment(comment_id, user_id, value, *args, **kwargs):
return
_perform_request
(
'put'
,
_url_for_vote_comment
(
comment_id
),
{
'user_id'
:
user_id
,
'value'
:
value
},
*
args
,
**
kwargs
)
def
undo_vote_for_comment
(
comment_id
,
user_id
,
*
args
,
**
kwargs
):
return
_perform_request
(
'delete'
,
_url_for_vote_comment
(
comment_id
),
*
args
,
**
kwargs
)
return
_perform_request
(
'delete'
,
_url_for_vote_comment
(
comment_id
),
{
'user_id'
:
user_id
},
*
args
,
**
kwargs
)
def
vote_for_thread
(
thread_id
,
user_id
,
value
,
*
args
,
**
kwargs
):
return
_perform_request
(
'put'
,
_url_for_vote_thread
(
thread_id
),
{
'user_id'
:
user_id
,
'value'
:
value
},
*
args
,
**
kwargs
)
def
undo_vote_for_thread
(
thread_id
,
user_id
,
*
args
,
**
kwargs
):
return
_perform_request
(
'delete'
,
_url_for_vote_thread
(
thread_id
),
*
args
,
**
kwargs
)
return
_perform_request
(
'delete'
,
_url_for_vote_thread
(
thread_id
),
{
'user_id'
:
user_id
},
*
args
,
**
kwargs
)
def
get_notifications
(
user_id
,
*
args
,
**
kwargs
):
return
_perform_request
(
'get'
,
_url_for_notifications
(
user_id
),
*
args
,
**
kwargs
)
...
...
@@ -108,8 +108,6 @@ def unsubscribe_thread(user_id, thread_id, *args, **kwargs):
def
unsubscribe_commentable
(
user_id
,
commentable_id
,
*
args
,
**
kwargs
):
return
unsubscribe
(
user_id
,
{
'source_type'
:
'other'
,
'source_id'
:
commentable_id
})
def
_perform_request
(
method
,
url
,
data_or_params
=
None
,
*
args
,
**
kwargs
):
if
method
in
[
'post'
,
'put'
,
'patch'
]:
response
=
requests
.
request
(
method
,
url
,
data
=
data_or_params
)
...
...
lms/static/coffee/src/discussion/content.coffee
View file @
600beb28
...
...
@@ -71,13 +71,34 @@ Discussion = @Discussion
$discussionContent
.
attr
(
"status"
,
"normal"
)
)
handleUnvote
=
(
elem
)
->
handleVote
=
(
elem
,
value
)
->
contentType
=
if
$content
.
hasClass
(
"thread"
)
then
"thread"
else
"comment"
url
=
Discussion
.
urlFor
(
"
#{
value
}
vote_
#{
contentType
}
"
,
id
)
$
.
post
url
,
{},
(
response
,
textStatus
)
->
if
textStatus
==
"success"
Discussion
.
handleAnchorAndReload
(
response
)
,
'json'
Discussion
.
safeAjax
$elem
:
$local
(
".discussion-vote"
)
url
:
url
type
:
"POST"
dataType
:
"json"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
$local
(
".discussion-vote"
).
removeClass
(
"voted"
)
$local
(
".discussion-vote-
#{
value
}
"
).
addClass
(
"voted"
)
$local
(
".discussion-votes-point"
).
html
response
.
votes
.
point
handleUnvote
=
(
elem
,
value
)
->
contentType
=
if
$content
.
hasClass
(
"thread"
)
then
"thread"
else
"comment"
url
=
Discussion
.
urlFor
(
"undo_vote_for_
#{
contentType
}
"
,
id
)
Discussion
.
safeAjax
$elem
:
$local
(
".discussion-vote"
)
url
:
url
type
:
"POST"
dataType
:
"json"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
$local
(
".discussion-vote"
).
removeClass
(
"voted"
)
$local
(
".discussion-votes-point"
).
html
response
.
votes
.
point
handleCancelEdit
=
(
elem
)
->
$local
(
".discussion-content-edit"
).
hide
()
...
...
@@ -213,10 +234,18 @@ Discussion = @Discussion
handleCancelReply
(
this
)
"click .discussion-vote-up"
:
->
handleVote
(
this
,
"up"
)
$elem
=
$
(
this
)
if
$elem
.
hasClass
(
"voted"
)
handleUnvote
(
$elem
)
else
handleVote
(
$elem
,
"up"
)
"click .discussion-vote-down"
:
->
handleVote
(
this
,
"down"
)
$elem
=
$
(
this
)
if
$elem
.
hasClass
(
"voted"
)
handleUnvote
(
$elem
)
else
handleVote
(
$elem
,
"down"
)
"click .discussion-endorse"
:
->
handleEndorse
(
this
)
...
...
lms/static/coffee/src/discussion/discussion.coffee
View file @
600beb28
...
...
@@ -76,7 +76,7 @@ initializeFollowThread = (index, thread) ->
$discussion
=
$
(
discussion
)
$discussionNonContent
=
$discussion
.
children
(
".discussion-non-content"
)
$local
=
Discussion
.
generateLocal
(
$discussionNonContent
)
#(selector) -> $discussionNonContent.find(selector)
$local
=
Discussion
.
generateLocal
(
$discussionNonContent
)
id
=
$discussion
.
attr
(
"_id"
)
...
...
lms/static/coffee/src/discussion/utils.coffee
View file @
600beb28
...
...
@@ -26,6 +26,7 @@ wmdEditors = {}
delete_thread
:
"/courses/
#{
$$course_id
}
/discussion/threads/
#{
param
}
/delete"
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"
follow_thread
:
"/courses/
#{
$$course_id
}
/discussion/threads/
#{
param
}
/follow"
unfollow_thread
:
"/courses/
#{
$$course_id
}
/discussion/threads/
#{
param
}
/unfollow"
update_comment
:
"/courses/
#{
$$course_id
}
/discussion/comments/
#{
param
}
/update"
...
...
@@ -34,6 +35,7 @@ wmdEditors = {}
delete_comment
:
"/courses/
#{
$$course_id
}
/discussion/comments/
#{
param
}
/delete"
upvote_comment
:
"/courses/
#{
$$course_id
}
/discussion/comments/
#{
param
}
/upvote"
downvote_comment
:
"/courses/
#{
$$course_id
}
/discussion/comments/
#{
param
}
/downvote"
undo_vote_for_comment
:
"/courses/
#{
$$course_id
}
/discussion/comments/
#{
param
}
/unvote"
upload
:
"/courses/
#{
$$course_id
}
/discussion/upload"
search
:
"/courses/
#{
$$course_id
}
/discussion/forum/search"
tags_autocomplete
:
"/courses/
#{
$$course_id
}
/discussion/threads/tags/autocomplete"
...
...
lms/templates/discussion/_thread.html
View file @
600beb28
...
...
@@ -108,7 +108,7 @@
<
%
def
name=
"render_vote(content)"
>
<div
class=
"discussion-votes"
>
${render_link("discussion-vote discussion-vote-up", "
˄
")}
${content['votes']['point']}
<div
class=
"discussion-votes-point"
>
${content['votes']['point']}
</div>
${render_link("discussion-vote discussion-vote-down", "
˅
")}
</div>
</
%
def>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment