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
44f7b37b
Commit
44f7b37b
authored
Aug 12, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored comment_client working
parent
b7d33618
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
80 deletions
+68
-80
lms/djangoapps/django_comment_client/base/views.py
+58
-59
lms/djangoapps/django_comment_client/forum/views.py
+6
-7
lms/static/coffee/src/discussion/content.coffee
+0
-2
lms/static/coffee/src/discussion/discussion.coffee
+0
-1
lms/static/coffee/src/discussion/utils.coffee
+0
-1
lms/templates/discussion/_inline.html
+4
-10
No files found.
lms/djangoapps/django_comment_client/base/views.py
View file @
44f7b37b
...
...
@@ -5,7 +5,7 @@ import os.path
import
logging
import
urlparse
import
comment_client
as
c
import
comment_client
as
c
c
from
django.core
import
exceptions
from
django.contrib.auth.decorators
import
login_required
...
...
@@ -19,7 +19,6 @@ from mitxmako.shortcuts import render_to_response, render_to_string
from
django_comment_client.utils
import
JsonResponse
,
JsonError
,
extract
from
django_comment_client.permissions
import
check_permissions_by_view
from
collection
import
defaultdict
import
functools
def
permitted
(
fn
):
...
...
@@ -27,9 +26,9 @@ def permitted(fn):
def
wrapper
(
request
,
*
args
,
**
kwargs
):
def
fetch_content
():
if
"thread_id"
in
kwargs
:
content
=
dict
(
c
.
Thread
.
find
(
kwargs
[
"thread_id"
])
)
content
=
cc
.
Thread
.
find
(
kwargs
[
"thread_id"
])
.
to_dict
(
)
elif
"comment_id"
in
kwargs
:
content
=
dict
(
c
.
Comment
.
find
(
kwargs
[
"comment_id"
])
)
content
=
cc
.
Comment
.
find
(
kwargs
[
"comment_id"
])
.
to_dict
(
)
else
:
content
=
None
return
content
...
...
@@ -45,71 +44,71 @@ def permitted(fn):
@permitted
def
create_thread
(
request
,
course_id
,
commentable_id
):
post
=
request
.
POST
thread
=
c
.
Thread
(
**
extract
(
post
,
[
'body'
,
'title'
,
'tags'
]))
thread
=
c
c
.
Thread
(
**
extract
(
post
,
[
'body'
,
'title'
,
'tags'
]))
thread
.
anonymous
=
post
.
get
(
'anonymous'
,
'false'
)
.
lower
()
==
'true'
thread
.
course_id
=
course_id
thread
.
user_id
=
request
.
user
.
id
thread
.
save
()
if
post
.
get
(
'auto_subscribe'
,
'false'
)
.
lower
()
==
'true'
:
user
=
c
.
User
.
from_django_user
(
request
.
user
)
user
.
subscribe
(
thread
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
user
.
follow
(
thread
)
if
request
.
is_ajax
():
context
=
{
'course_id'
:
course_id
,
'thread'
:
dict
(
thread
),
'thread'
:
thread
.
to_dict
(
),
}
html
=
render_to_string
(
'discussion/ajax_create_thread.html'
,
context
)
return
JsonResponse
({
'html'
:
html
,
'content'
:
dict
(
thread
),
'content'
:
thread
.
to_dict
(
),
})
else
:
return
JsonResponse
(
dict
(
thread
))
return
JsonResponse
(
thread
.
to_dict
(
))
@require_POST
@login_required
@permitted
def
update_thread
(
request
,
course_id
,
thread_id
):
thread
=
c
.
Thread
.
find
(
thread_id
)
thread
=
c
c
.
Thread
.
find
(
thread_id
)
thread
.
update_attributes
(
**
extract
(
request
.
POST
,
[
'body'
,
'title'
,
'tags'
]))
thread
.
save
()
if
request
.
is_ajax
():
context
=
{
'thread'
:
dict
(
thread
),
'thread'
:
thread
.
to_dict
(
),
'course_id'
:
course_id
,
}
html
=
render_to_string
(
'discussion/ajax_update_thread.html'
,
context
)
return
JsonResponse
({
'html'
:
html
,
'content'
:
dict
(
thread
),
'content'
:
thread
.
to_dict
(
),
})
else
:
return
JsonResponse
(
dict
(
thread
))
return
JsonResponse
(
thread
.
to_dict
(
))
def
_create_comment
(
request
,
course_id
,
thread_id
=
None
,
parent_id
=
None
):
post
=
request
.
POST
comment
=
c
.
Comment
(
**
extract
(
post
,
[
'body'
]))
comment
=
c
c
.
Comment
(
**
extract
(
post
,
[
'body'
]))
comment
.
anonymous
=
post
.
get
(
'anonymous'
,
'false'
)
.
lower
()
==
'true'
comment
.
user_id
=
request
.
user
.
id
comment
.
course_id
=
course_id
comment
.
thread_id
=
thread_id
comment
.
parent_id
=
parent_id
comment
.
save
()
dict_comment
=
dict
(
comment
)
dict_comment
=
comment
.
to_dict
(
)
if
post
.
get
(
'auto_subscribe'
,
'false'
)
.
lower
()
==
'true'
:
user
=
c
.
User
.
from_django_user
(
request
.
user
)
user
.
subscribe
(
comment
.
thread
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
user
.
follow
(
comment
.
thread
)
if
request
.
is_ajax
():
context
=
{
'comment'
:
dict
(
comment
),
'comment'
:
comment
.
to_dict
(
),
}
html
=
render_to_string
(
'discussion/ajax_create_comment.html'
,
context
)
return
JsonResponse
({
'html'
:
html
,
'content'
:
dict
(
comment
),
'content'
:
comment
.
to_dict
(
),
})
else
:
return
JsonResponse
(
dict
(
comment
))
return
JsonResponse
(
comment
.
to_dict
(
))
@require_POST
@login_required
...
...
@@ -121,47 +120,47 @@ def create_comment(request, course_id, thread_id):
@login_required
@permitted
def
delete_thread
(
request
,
course_id
,
thread_id
):
thread
=
c
.
Thread
.
find
(
thread_id
)
thread
=
c
c
.
Thread
.
find
(
thread_id
)
thread
.
delete
()
return
JsonResponse
(
dict
(
thread
))
return
JsonResponse
(
thread
.
to_dict
(
))
@require_POST
@login_required
@permitted
def
update_comment
(
request
,
course_id
,
comment_id
):
comment
=
c
.
Comment
.
find
(
comment_id
)
comment
=
c
c
.
Comment
.
find
(
comment_id
)
comment
.
update_attributes
(
**
extract
(
request
.
POST
,
[
'body'
]))
comment
.
save
()
if
request
.
is_ajax
():
context
=
{
'comment'
:
dict
(
comment
),
'comment'
:
comment
.
to_dict
(
),
'course_id'
:
course_id
,
}
html
=
render_to_string
(
'discussion/ajax_update_comment.html'
,
context
)
return
JsonResponse
({
'html'
:
html
,
'content'
:
dict
(
comment
),
'content'
:
comment
.
to_dict
(
),
})
else
:
return
JsonResponse
(
dict
(
comment
)),
return
JsonResponse
(
comment
.
to_dict
(
)),
@require_POST
@login_required
@permitted
def
endorse_comment
(
request
,
course_id
,
comment_id
):
comment
=
c
.
Comment
.
find
(
comment_id
)
comment
=
c
c
.
Comment
.
find
(
comment_id
)
comment
.
endorsed
=
request
.
POST
.
get
(
'endorsed'
,
'false'
)
.
lower
()
==
'true'
comment
.
save
()
return
JsonResponse
(
dict
(
response
))
return
JsonResponse
(
comment
.
to_dict
(
))
@require_POST
@login_required
@permitted
def
openclose_thread
(
request
,
course_id
,
thread_id
):
comment
=
c
.
Comment
.
find
(
comment_id
)
comment
=
c
c
.
Comment
.
find
(
comment_id
)
comment
.
endorsed
=
request
.
POST
.
get
(
'closed'
,
'false'
)
.
lower
()
==
'true'
comment
.
save
()
return
JsonResponse
(
dict
(
response
))
return
JsonResponse
(
comment
.
to_dict
(
))
@require_POST
@login_required
...
...
@@ -173,53 +172,53 @@ def create_sub_comment(request, course_id, comment_id):
@login_required
@permitted
def
delete_comment
(
request
,
course_id
,
comment_id
):
comment
=
c
.
Comment
.
find
(
comment_id
)
comment
=
c
c
.
Comment
.
find
(
comment_id
)
comment
.
delete
()
return
JsonResponse
(
dict
(
response
))
return
JsonResponse
(
comment
.
to_dict
(
))
@require_POST
@login_required
@permitted
def
vote_for_comment
(
request
,
course_id
,
comment_id
,
value
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
comment
=
c
.
Comment
.
find
(
comment_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
comment
=
c
c
.
Comment
.
find
(
comment_id
)
user
.
vote
(
comment
,
value
)
return
JsonResponse
(
dict
(
comment
))
return
JsonResponse
(
comment
.
to_dict
(
))
@require_POST
@login_required
@permitted
def
undo_vote_for_comment
(
request
,
course_id
,
comment_id
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
comment
=
c
.
Comment
.
find
(
comment_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
comment
=
c
c
.
Comment
.
find
(
comment_id
)
user
.
unvote
(
comment
)
return
JsonResponse
(
dict
(
comment
))
return
JsonResponse
(
comment
.
to_dict
(
))
@require_POST
@login_required
@permitted
def
vote_for_thread
(
request
,
course_id
,
thread_id
,
value
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
thread
=
c
.
Thread
.
find
(
thread_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
thread
=
c
c
.
Thread
.
find
(
thread_id
)
user
.
vote
(
thread
,
value
)
return
JsonResponse
(
dict
(
thread
))
return
JsonResponse
(
thread
.
to_dict
(
))
@require_POST
@login_required
@permitted
def
undo_vote_for_thread
(
request
,
course_id
,
thread_id
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
thread
=
c
.
Thread
.
find
(
thread_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
thread
=
c
c
.
Thread
.
find
(
thread_id
)
user
.
unvote
(
thread
)
return
JsonResponse
(
dict
(
thread
))
return
JsonResponse
(
thread
.
to_dict
(
))
@require_POST
@login_required
@permitted
def
follow_thread
(
request
,
course_id
,
thread_id
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
thread
=
c
.
Thread
.
find
(
thread_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
thread
=
c
c
.
Thread
.
find
(
thread_id
)
user
.
follow
(
thread
)
return
JsonResponse
({})
...
...
@@ -227,8 +226,8 @@ def follow_thread(request, course_id, thread_id):
@login_required
@permitted
def
follow_commentable
(
request
,
course_id
,
commentable_id
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
commentable
=
c
.
Commentable
.
find
(
commentable_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
commentable
=
c
c
.
Commentable
.
find
(
commentable_id
)
user
.
follow
(
commentable
)
return
JsonResponse
({})
...
...
@@ -236,8 +235,8 @@ def follow_commentable(request, course_id, commentable_id):
@login_required
@permitted
def
follow_user
(
request
,
course_id
,
followed_user_id
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
followed_user
=
c
.
User
.
find
(
followed_user_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
followed_user
=
c
c
.
User
.
find
(
followed_user_id
)
user
.
follow
(
followed_user
)
return
JsonResponse
({})
...
...
@@ -245,8 +244,8 @@ def follow_user(request, course_id, followed_user_id):
@login_required
@permitted
def
unfollow_thread
(
request
,
course_id
,
thread_id
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
thread
=
c
.
Thread
.
find
(
thread_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
thread
=
c
c
.
Thread
.
find
(
thread_id
)
user
.
unfollow
(
thread
)
return
JsonResponse
({})
...
...
@@ -254,8 +253,8 @@ def unfollow_thread(request, course_id, thread_id):
@login_required
@permitted
def
unfollow_commentable
(
request
,
course_id
,
commentable_id
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
commentable
=
c
.
Commentable
.
find
(
commentable_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
commentable
=
c
c
.
Commentable
.
find
(
commentable_id
)
user
.
unfollow
(
commentable
)
return
JsonResponse
({})
...
...
@@ -263,8 +262,8 @@ def unfollow_commentable(request, course_id, commentable_id):
@login_required
@permitted
def
unfollow_user
(
request
,
course_id
,
followed_user_id
):
user
=
c
.
User
.
from_django_user
(
request
.
user
)
followed_user
=
c
.
User
.
find
(
followed_user_id
)
user
=
c
c
.
User
.
from_django_user
(
request
.
user
)
followed_user
=
c
c
.
User
.
find
(
followed_user_id
)
user
.
unfollow
(
followed_user
)
return
JsonResponse
({})
...
...
@@ -273,7 +272,7 @@ def search_similar_threads(request, course_id, commentable_id):
text
=
request
.
GET
.
get
(
'text'
,
None
)
if
text
:
return
JsonResponse
(
c
.
search_similar_threads
(
c
c
.
search_similar_threads
(
course_id
,
recursive
=
False
,
query_params
=
{
...
...
@@ -289,7 +288,7 @@ def tags_autocomplete(request, course_id):
value
=
request
.
GET
.
get
(
'q'
,
None
)
results
=
[]
if
value
:
results
=
c
.
tags_autocomplete
(
value
)
results
=
c
c
.
tags_autocomplete
(
value
)
return
JsonResponse
(
results
)
@require_POST
...
...
lms/djangoapps/django_comment_client/forum/views.py
View file @
44f7b37b
...
...
@@ -59,7 +59,7 @@ def render_discussion(request, course_id, threads, discussion_id=None, \
context
=
{
'threads'
:
threads
,
'discussion_id'
:
discussion_id
,
'user_info'
:
dict
(
cc
.
User
.
from_django_user
(
request
.
user
)),
#comment_client.get_user_info(request.user.id, raw=True
),
'user_info'
:
json
.
dumps
(
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()
),
'course_id'
:
course_id
,
'request'
:
request
,
'performed_search'
:
_should_perform_search
(
request
),
...
...
@@ -90,7 +90,6 @@ def get_threads(request, course_id, discussion_id):
'course_id'
:
course_id
,
}
import
pdb
;
pdb
.
set_trace
()
threads
,
page
,
num_pages
=
cc
.
Thread
.
search
(
query_params
)
#if _should_perform_search(request):
...
...
@@ -172,16 +171,16 @@ def get_annotated_content_infos(course_id, thread, user, is_thread=True):
def
render_single_thread
(
request
,
discussion_id
,
course_id
,
thread_id
):
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
_with_comments
(
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
)
#comment_client.get_thread(thread_id, recursive=True)
annotated_content_info
=
get_annotated_content_infos
(
course_id
,
thread
=
dict
(
thread
),
\
annotated_content_info
=
get_annotated_content_infos
(
course_id
,
thread
=
thread
.
to_dict
(
),
\
user
=
request
.
user
,
is_thread
=
True
)
context
=
{
'discussion_id'
:
discussion_id
,
'thread'
:
thread
,
'user_info'
:
dict
(
cc
.
User
.
from_django_user
(
request
.
user
)
),
#get_user_info(request.user.id, raw=True),
'user_info'
:
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
(
),
#get_user_info(request.user.id, raw=True),
'annotated_content_info'
:
json
.
dumps
(
annotated_content_info
),
'course_id'
:
course_id
,
'request'
:
request
,
...
...
@@ -192,9 +191,9 @@ def single_thread(request, course_id, discussion_id, thread_id):
if
request
.
is_ajax
():
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
_with_comments
()
#comment_client.get_thread(thread_id,
recursive=True)
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
)
annotated_content_info
=
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
)
context
=
{
'thread'
:
dict
(
thread
)}
context
=
{
'thread'
:
thread
.
to_dict
(
)}
html
=
render_to_string
(
'discussion/_ajax_single_thread.html'
,
context
)
return
utils
.
JsonResponse
({
...
...
lms/static/coffee/src/discussion/content.coffee
View file @
44f7b37b
...
...
@@ -183,8 +183,6 @@ initializeFollowThread = (thread) ->
handleEndorse
=
(
elem
,
endorsed
)
->
url
=
Discussion
.
urlFor
(
'endorse_comment'
,
id
)
console
.
log
endorsed
console
.
log
url
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
...
...
lms/static/coffee/src/discussion/discussion.coffee
View file @
44f7b37b
...
...
@@ -79,7 +79,6 @@ initializeFollowDiscussion = (discussion) ->
data
:
text
:
$local
(
".new-post-title"
).
val
()
success
:
(
response
,
textStatus
)
->
console
.
log
"request"
$similarPosts
.
empty
()
if
$
.
type
(
response
)
==
"array"
and
response
.
length
$wrapper
.
show
()
...
...
lms/static/coffee/src/discussion/utils.coffee
View file @
44f7b37b
...
...
@@ -116,7 +116,6 @@ wmdEditors = {}
appended_id
=
"-
#{
cls_identifier
}
-
#{
id
}
"
imageUploadUrl
=
Discussion
.
urlFor
(
'upload'
)
editor
=
Markdown
.
makeWmdEditor
elem
,
appended_id
,
imageUploadUrl
,
Discussion
.
postMathJaxProcessor
console
.
log
editor
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
=
editor
$input
=
$
(
"#wmd-input-
#{
cls_identifier
}
-
#{
id
}
"
)
$input
.
attr
(
"placeholder"
,
"post a new topic..."
).
bind
'focus'
,
(
e
)
->
...
...
lms/templates/discussion/_inline.html
View file @
44f7b37b
<
%
namespace
name=
"renderer"
file=
"_thread.html"
/>
<
%!
from
django
.
template
.
defaultfilters
import
escapejs
%
>
<section
class=
"discussion inline-discussion"
_id=
"${discussion_id}"
>
...
...
@@ -27,18 +28,11 @@
<
%
include
file=
"_paginator.html"
/>
</section>
<
%!
def
escape_quotes
(
text
)
:
return
text
.
replace
('\"',
'\\\"').
replace
("\'",
"\\\'")
%
>
<script
type=
"text/javascript"
>
var
$$user_info
=
JSON
.
parse
(
'${user_info | escape_quotes}'
);
var
$$course_id
=
"${course_id}"
;
var
$$user_info
=
JSON
.
parse
(
"${user_info | escapejs}"
);
var
$$course_id
=
"${course_id
| escapejs
}"
;
if
(
typeof
$$annotated_content_info
===
undefined
||
$$annotated_content_info
===
null
)
{
var
$$annotated_content_info
=
{};
}
$$annotated_content_info
=
$
.
extend
(
$$annotated_content_info
,
JSON
.
parse
(
"${annotated_content_info | escape
_quote
s}"
));
$$annotated_content_info
=
$
.
extend
(
$$annotated_content_info
,
JSON
.
parse
(
"${annotated_content_info | escape
j
s}"
));
</script>
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