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
fdf92d68
Commit
fdf92d68
authored
Aug 21, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more refactoring; enabled partial re-rendering for votes, endorse, and closed
parent
72e6588b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
71 additions
and
65 deletions
+71
-65
lms/djangoapps/django_comment_client/base/views.py
+2
-1
lms/djangoapps/django_comment_client/forum/views.py
+11
-7
lms/djangoapps/django_comment_client/utils.py
+21
-12
lms/static/coffee/src/backbone_discussion/content.coffee
+0
-0
lms/static/coffee/src/backbone_discussion/discussion.coffee
+2
-1
lms/static/coffee/src/backbone_discussion/main.coffee
+5
-0
lms/static/coffee/src/backbone_discussion/utils.coffee
+27
-39
lms/static/coffee/src/discussion/content.coffee
+1
-0
lms/templates/discussion/_content_renderer.html
+2
-4
lms/templates/discussion/_js_data.html
+0
-1
No files found.
lms/djangoapps/django_comment_client/base/views.py
View file @
fdf92d68
...
...
@@ -51,7 +51,8 @@ def ajax_content_response(request, course_id, content, template_name):
'content'
:
content
,
}
html
=
render_to_string
(
template_name
,
context
)
annotated_content_info
=
utils
.
get_annotated_content_info
(
course_id
,
content
,
request
.
user
)
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()
annotated_content_info
=
utils
.
get_annotated_content_info
(
course_id
,
content
,
request
.
user
,
user_info
)
return
JsonResponse
({
'html'
:
html
,
'content'
:
content
,
...
...
lms/djangoapps/django_comment_client/forum/views.py
View file @
fdf92d68
...
...
@@ -15,7 +15,6 @@ from django_comment_client.permissions import check_permissions_by_view
from
django_comment_client.utils
import
merge_dict
,
extract
,
strip_none
import
json
import
dateutil
import
django_comment_client.utils
as
utils
import
comment_client
as
cc
...
...
@@ -64,14 +63,17 @@ def render_discussion(request, course_id, threads, *args, **kwargs):
'user'
:
(
lambda
:
reverse
(
'django_comment_client.forum.views.user_profile'
,
args
=
[
course_id
,
user_id
])),
}[
discussion_type
]()
annotated_content_infos
=
map
(
lambda
x
:
utils
.
get_annotated_content_infos
(
course_id
,
x
,
request
.
user
),
threads
)
annotated_content_info
=
reduce
(
merge_dict
,
annotated_content_infos
,
{})
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()
def
infogetter
(
thread
):
return
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
)
annotated_content_info
=
reduce
(
merge_dict
,
map
(
infogetter
,
threads
),
{})
context
=
{
'threads'
:
threads
,
'discussion_id'
:
discussion_id
,
'user_id'
:
user_id
,
'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
),
...
...
@@ -166,12 +168,13 @@ def render_single_thread(request, discussion_id, course_id, thread_id):
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
)
.
to_dict
()
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
=
thread
,
user
=
request
.
user
)
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
=
thread
,
user
=
request
.
user
,
user_info
=
user_info
)
context
=
{
'discussion_id'
:
discussion_id
,
'thread'
:
thread
,
'user_info'
:
json
.
dumps
(
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()),
'annotated_content_info'
:
json
.
dumps
(
annotated_content_info
),
'course_id'
:
course_id
,
'request'
:
request
,
...
...
@@ -183,8 +186,9 @@ def single_thread(request, course_id, discussion_id, thread_id):
if
request
.
is_ajax
():
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
)
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
)
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
=
user_info
)
context
=
{
'thread'
:
thread
.
to_dict
(),
'course_id'
:
course_id
}
html
=
render_to_string
(
'discussion/_ajax_single_thread.html'
,
context
)
...
...
lms/djangoapps/django_comment_client/utils.py
View file @
fdf92d68
...
...
@@ -160,23 +160,32 @@ class QueryCountDebugMiddleware(object):
logging
.
info
(
'
%
s queries run, total
%
s seconds'
%
(
len
(
connection
.
queries
),
total_time
))
return
response
def
get_annotated_content_info
(
course_id
,
content
,
user
):
def
get_annotated_content_info
(
course_id
,
content
,
user
,
user_info
):
voted
=
''
if
content
[
'id'
]
in
user_info
[
'upvoted_ids'
]:
voted
=
'up'
elif
content
[
'id'
]
in
user_info
[
'downvoted_ids'
]:
voted
=
'down'
return
{
'editable'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"update_thread"
if
content
[
'type'
]
==
'thread'
else
"update_comment"
),
'can_reply'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"create_comment"
if
content
[
'type'
]
==
'thread'
else
"create_sub_comment"
),
'can_endorse'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"endorse_comment"
)
if
content
[
'type'
]
==
'comment'
else
False
,
'can_delete'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"delete_thread"
if
content
[
'type'
]
==
'thread'
else
"delete_comment"
),
'can_openclose'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"openclose_thread"
)
if
content
[
'type'
]
==
'thread'
else
False
,
'can_vote'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"vote_for_thread"
if
content
[
'type'
]
==
'thread'
else
"vote_for_comment"
),
'voted'
:
voted
,
'subscribed'
:
content
[
'id'
]
in
user_info
[
'subscribed_thread_ids'
],
'ability'
:
{
'editable'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"update_thread"
if
content
[
'type'
]
==
'thread'
else
"update_comment"
),
'can_reply'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"create_comment"
if
content
[
'type'
]
==
'thread'
else
"create_sub_comment"
),
'can_endorse'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"endorse_comment"
)
if
content
[
'type'
]
==
'comment'
else
False
,
'can_delete'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"delete_thread"
if
content
[
'type'
]
==
'thread'
else
"delete_comment"
),
'can_openclose'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"openclose_thread"
)
if
content
[
'type'
]
==
'thread'
else
False
,
'can_vote'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"vote_for_thread"
if
content
[
'type'
]
==
'thread'
else
"vote_for_comment"
),
},
}
def
get_annotated_content_infos
(
course_id
,
thread
,
user
):
def
get_annotated_content_infos
(
course_id
,
thread
,
user
,
user_info
):
infos
=
{}
def
_
annotate
(
content
):
infos
[
str
(
content
[
'id'
])]
=
get_annotated_content_info
(
course_id
,
content
,
user
)
def
annotate
(
content
):
infos
[
str
(
content
[
'id'
])]
=
get_annotated_content_info
(
course_id
,
content
,
user
,
user_info
)
for
child
in
content
.
get
(
'children'
,
[]):
_
annotate
(
child
)
_
annotate
(
thread
)
annotate
(
child
)
annotate
(
thread
)
return
infos
def
render_mustache
(
template_name
,
dictionary
,
*
args
,
**
kwargs
):
...
...
lms/static/coffee/src/backbone_discussion/content.coffee
View file @
fdf92d68
This diff is collapsed.
Click to expand it.
lms/static/coffee/src/backbone_discussion/discussion.coffee
View file @
fdf92d68
class
@
Discussion
extends
Backbone
.
Collection
model
:
Thread
initialize
:
->
DiscussionUtil
.
addDiscussion
@
id
,
@
@
bind
"add"
,
(
item
)
=>
console
.
log
item
item
.
discussion
=
@
find
:
(
id
)
->
...
...
lms/static/coffee/src/backbone_discussion/main.coffee
View file @
fdf92d68
$
->
window
.
$
$contents
=
{}
window
.
$
$discussions
=
{}
$
(
".discussion-module"
).
each
(
index
,
elem
)
->
view
=
new
DiscussionModuleView
(
el
:
elem
)
...
...
@@ -8,3 +11,5 @@ $ ->
discussion
=
new
Discussion
()
discussion
.
reset
(
discussionData
,
{
silent
:
false
})
view
=
new
DiscussionView
(
el
:
elem
,
model
:
discussion
)
DiscussionUtil
.
bulkUpdateContentInfo
(
window
.
$
$annotated_content_info
)
lms/static/coffee/src/backbone_discussion/utils.coffee
View file @
fdf92d68
...
...
@@ -12,26 +12,17 @@ class @DiscussionUtil
id
=
$
(
id
).
attr
(
"_id"
)
return
$$discussion_data
[
id
]
@
getContentInfo
:
(
id
,
attr
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
(
window
.
$
$annotated_content_info
[
id
]
||
{})[
attr
]
@
setContentInfo
:
(
id
,
attr
,
value
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
window
.
$
$annotated_content_info
[
id
]
||=
{}
window
.
$
$annotated_content_info
[
id
][
attr
]
=
value
@
extendContentInfo
:
(
id
,
newInfo
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
window
.
$
$annotated_content_info
[
id
]
=
newInfo
@
bulkExtendContentInfo
:
(
newInfos
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
window
.
$
$annotated_content_info
=
$
.
extend
window
.
$
$annotated_content_info
,
newInfos
@
addContent
:
(
id
,
content
)
->
window
.
$
$contents
[
id
]
=
content
@
getContent
:
(
id
)
->
window
.
$
$contents
[
id
]
@
addDiscussion
:
(
id
,
discussion
)
->
window
.
$
$discussions
[
id
]
=
discussion
@
getDiscussion
:
(
id
)
->
window
.
$
$discussions
[
id
]
@
bulkUpdateContentInfo
:
(
infos
)
->
for
id
,
info
of
infos
@
getContent
(
id
).
updateInfo
(
info
)
@
generateDiscussionLink
:
(
cls
,
txt
,
handler
)
->
$
(
"<a>"
).
addClass
(
"discussion-link"
)
...
...
@@ -79,9 +70,22 @@ class @DiscussionUtil
$
.
ajax
(
params
).
always
->
$elem
.
removeAttr
(
"disabled"
)
@
handleAnchorAndReload
:
(
response
)
->
#window.location = window.location.pathname + "#" + response['id']
window
.
location
.
reload
()
@
get
:
(
$elem
,
url
,
success
)
->
@
safeAjax
$elem
:
$elem
url
:
url
type
:
"GET"
dataType
:
"json"
success
:
success
@
post
:
(
$elem
,
url
,
data
,
success
)
->
@
safeAjax
$elem
:
$elem
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
data
success
:
success
@
bindLocalEvents
:
(
$local
,
eventsHandler
)
->
for
eventSelector
,
handler
of
eventsHandler
...
...
@@ -98,22 +102,6 @@ class @DiscussionUtil
defaultText
:
"Tag your post: press enter after each tag"
removeWithBackspace
:
true
@
isSubscribed
:
(
id
,
type
)
->
$$user_info
?
and
(
if
type
==
"thread"
id
in
$$user_info
.
subscribed_thread_ids
else
if
type
==
"commentable"
or
type
==
"discussion"
id
in
$$user_info
.
subscribed_commentable_ids
else
id
in
$$user_info
.
subscribed_user_ids
)
@
isUpvoted
:
(
id
)
->
$$user_info
?
and
(
id
in
$$user_info
.
upvoted_ids
)
@
isDownvoted
:
(
id
)
->
$$user_info
?
and
(
id
in
$$user_info
.
downvoted_ids
)
@
formErrorHandler
:
(
errorsField
)
->
(
xhr
,
textStatus
,
error
)
->
response
=
JSON
.
parse
(
xhr
.
responseText
)
...
...
lms/static/coffee/src/discussion/content.coffee
View file @
fdf92d68
...
...
@@ -85,6 +85,7 @@ initializeFollowThread = (thread) ->
Discussion
.
extendContentInfo
response
.
content
[
'id'
],
response
[
'annotated_content_info'
]
Discussion
.
initializeContent
(
$comment
)
Discussion
.
bindContentEvents
(
$comment
)
@
cancelReply
()
$local
(
".discussion-reply-new"
).
hide
()
$local
(
".discussion-reply"
).
show
()
$local
(
".discussion-edit"
).
show
()
...
...
lms/templates/discussion/_content_renderer.html
View file @
fdf92d68
...
...
@@ -5,11 +5,9 @@
</
%
def>
<
%
def
name=
"render_content_with_comments(content)"
>
<div
class=
"${content['type']}${helpers.show_if(' endorsed', content.get('endorsed'))}"
_id=
"${content['id']}"
_discussion_id=
"${content.get('commentable_id', '')}"
_author_id=
"${helpers.show_if(content['user_id'], not content.get('anonymous'))}"
>
<div
class=
"${content['type']}${helpers.show_if(' endorsed', content.get('endorsed'))}"
_id=
"${content['id']}"
_discussion_id=
"${content.get('commentable_id', '')}"
_author_id=
"${helpers.show_if(content['user_id'], not content.get('anonymous'))}"
>
${render_content(content)}
% if content.get('children') is not None:
${render_comments(content['children'])}
% endif
${render_comments(content.get('children', []))}
</div>
</
%
def>
...
...
lms/templates/discussion/_js_data.html
View file @
fdf92d68
<
%!
from
django
.
template
.
defaultfilters
import
escapejs
%
>
<script
type=
"text/javascript"
>
var
$$user_info
=
JSON
.
parse
(
"${user_info | escapejs}"
);
var
$$course_id
=
"${course_id | escapejs}"
;
if
(
typeof
$$annotated_content_info
===
undefined
)
{
var
$$annotated_content_info
=
{};
...
...
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