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
e5fe54ca
Commit
e5fe54ca
authored
Aug 15, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
display active threads with only relevant contents
parent
9ef1a11c
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
114 additions
and
26 deletions
+114
-26
lms/djangoapps/django_comment_client/base/views.py
+0
-0
lms/djangoapps/django_comment_client/forum/views.py
+33
-4
lms/djangoapps/django_comment_client/permissions.py
+0
-1
lms/djangoapps/django_comment_client/utils.py
+4
-1
lms/lib/comment_client/user.py
+12
-0
lms/static/coffee/src/discussion/content.coffee
+14
-5
lms/static/coffee/src/discussion/discussion.coffee
+5
-3
lms/static/coffee/src/discussion/user_profile.coffee
+2
-0
lms/static/sass/_discussion.scss
+1
-1
lms/templates/discussion/_thread.html
+17
-10
lms/templates/discussion/_user_active_threads.html
+24
-0
lms/templates/discussion/user_profile.html
+2
-1
No files found.
lms/djangoapps/django_comment_client/base/views.py
View file @
e5fe54ca
lms/djangoapps/django_comment_client/forum/views.py
View file @
e5fe54ca
...
...
@@ -41,24 +41,35 @@ def render_accordion(request, course, discussion_id):
return
render_to_string
(
'discussion/_accordion.html'
,
context
)
def
render_discussion
(
request
,
course_id
,
threads
,
discussion_id
=
None
,
\
discussion_type
=
'inline'
,
query_params
=
{}):
def
render_discussion
(
request
,
course_id
,
threads
,
*
args
,
**
kwargs
):
discussion_id
=
kwargs
.
get
(
'discussion_id'
)
user_id
=
kwargs
.
get
(
'user_id'
)
discussion_type
=
kwargs
.
get
(
'discussion_type'
,
'inline'
)
query_params
=
kwargs
.
get
(
'query_params'
,
{})
template
=
{
'inline'
:
'discussion/_inline.html'
,
'forum'
:
'discussion/_forum.html'
,
'user'
:
'discussion/_user_active_threads.html'
,
}[
discussion_type
]
base_url
=
{
'inline'
:
(
lambda
:
reverse
(
'django_comment_client.forum.views.inline_discussion'
,
args
=
[
course_id
,
discussion_id
])),
'forum'
:
(
lambda
:
reverse
(
'django_comment_client.forum.views.forum_form_discussion'
,
args
=
[
course_id
,
discussion_id
])),
'user'
:
(
lambda
:
reverse
(
'django_comment_client.forum.views.user_profile'
,
args
=
[
course_id
,
user_id
])),
}[
discussion_type
]()
annotated_content_info
=
{
thread
[
'id'
]:
utils
.
get_annotated_content_info
(
course_id
,
thread
,
request
.
user
,
type
=
'thread'
)
for
thread
in
threads
}
print
"start annotating"
annotated_content_infos
=
map
(
lambda
x
:
utils
.
get_annotated_content_infos
(
course_id
,
x
,
request
.
user
,
type
=
'thread'
),
threads
)
print
"start merging annotations"
annotated_content_info
=
reduce
(
utils
.
merge_dict
,
annotated_content_infos
,
{})
print
"finished annotating"
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
,
...
...
@@ -78,6 +89,9 @@ def render_inline_discussion(*args, **kwargs):
def
render_forum_discussion
(
*
args
,
**
kwargs
):
return
render_discussion
(
discussion_type
=
'forum'
,
*
args
,
**
kwargs
)
def
render_user_discussion
(
*
args
,
**
kwargs
):
return
render_discussion
(
discussion_type
=
'user'
,
*
args
,
**
kwargs
)
def
get_threads
(
request
,
course_id
,
discussion_id
):
query_params
=
{
'page'
:
request
.
GET
.
get
(
'page'
,
1
),
...
...
@@ -194,14 +208,29 @@ def single_thread(request, course_id, discussion_id, thread_id):
def
user_profile
(
request
,
course_id
,
user_id
):
course
=
check_course
(
request
.
user
,
course_id
)
discussion_user
=
cc
.
User
(
id
=
user_id
,
course_id
=
course_id
)
query_params
=
{
'page'
:
request
.
GET
.
get
(
'page'
,
1
),
'per_page'
:
THREADS_PER_PAGE
,
# more than threads_per_page to show more activities
}
threads
,
page
,
num_pages
=
discussion_user
.
active_threads
(
query_params
)
query_params
[
'page'
]
=
page
query_params
[
'num_pages'
]
=
num_pages
content
=
render_user_discussion
(
request
,
course_id
,
threads
,
user_id
=
user_id
,
query_params
=
query_params
)
if
request
.
is_ajax
():
return
utils
.
HtmlResponse
(
content
)
else
:
context
=
{
'course'
:
course
,
'user'
:
request
.
user
,
'django_user'
:
User
.
objects
.
get
(
id
=
user_id
),
'discussion_user'
:
discussion_user
.
to_dict
(),
'content'
:
content
,
}
return
render_to_response
(
'discussion/user_profile.html'
,
context
)
lms/djangoapps/django_comment_client/permissions.py
View file @
e5fe54ca
...
...
@@ -96,7 +96,6 @@ VIEW_PERMISSIONS = {
def
check_permissions_by_view
(
user
,
course_id
,
content
,
name
):
# import pdb; pdb.set_trace()
try
:
p
=
VIEW_PERMISSIONS
[
name
]
except
KeyError
:
...
...
lms/djangoapps/django_comment_client/utils.py
View file @
e5fe54ca
...
...
@@ -16,13 +16,16 @@ _FULLMODULES = None
_DISCUSSIONINFO
=
None
def
extract
(
dic
,
keys
):
return
{
k
:
dic
[
k
]
for
k
in
keys
}
return
{
k
:
dic
.
get
(
k
)
for
k
in
keys
}
def
strip_none
(
dic
):
def
_is_none
(
v
):
return
v
is
None
or
(
isinstance
(
v
,
str
)
and
len
(
v
.
strip
())
==
0
)
return
dict
([(
k
,
v
)
for
k
,
v
in
dic
.
iteritems
()
if
not
_is_none
(
v
)])
def
merge_dict
(
dic1
,
dic2
):
return
dict
(
dic1
.
items
()
+
dic2
.
items
())
def
get_full_modules
():
global
_FULLMODULES
if
not
_FULLMODULES
:
...
...
lms/lib/comment_client/user.py
View file @
e5fe54ca
...
...
@@ -55,6 +55,15 @@ class User(models.Model):
request
=
perform_request
(
'delete'
,
url
,
params
)
voteable
.
update_attributes
(
request
)
def
active_threads
(
self
,
query_params
=
{}):
if
not
self
.
course_id
:
raise
CommentClientError
(
"Must provide course_id when retrieving active threads for the user"
)
url
=
_url_for_user_active_threads
(
self
.
id
)
params
=
{
'course_id'
:
self
.
course_id
}
params
=
merge_dict
(
params
,
query_params
)
response
=
perform_request
(
'get'
,
url
,
params
)
return
response
.
get
(
'collection'
,
[]),
response
.
get
(
'page'
,
1
),
response
.
get
(
'num_pages'
,
1
)
def
_retrieve
(
self
,
*
args
,
**
kwargs
):
url
=
self
.
url
(
action
=
'get'
,
params
=
self
.
attributes
)
retrieve_params
=
self
.
default_retrieve_params
...
...
@@ -71,3 +80,6 @@ def _url_for_vote_thread(thread_id):
def
_url_for_subscription
(
user_id
):
return
"{prefix}/users/{user_id}/subscriptions"
.
format
(
prefix
=
settings
.
PREFIX
,
user_id
=
user_id
)
def
_url_for_user_active_threads
(
user_id
):
return
"{prefix}/users/{user_id}/active_threads"
.
format
(
prefix
=
settings
.
PREFIX
,
user_id
=
user_id
)
lms/static/coffee/src/discussion/content.coffee
View file @
e5fe54ca
...
...
@@ -252,12 +252,14 @@ initializeFollowThread = (thread) ->
handleHideSingleThread
=
(
elem
)
->
$threadTitle
=
$local
(
".thread-title"
)
$showComments
=
$local
(
".discussion-show-comments"
)
$hideComments
=
$local
(
".discussion-hide-comments"
)
$hideComments
.
removeClass
(
"discussion-hide-comments"
)
.
addClass
(
"discussion-show-comments"
)
$content
.
children
(
".comments"
).
hide
()
$threadTitle
.
unbind
(
'click'
).
click
handleShowSingleThread
$
show
Comments
.
unbind
(
'click'
).
click
handleShowSingleThread
prevHtml
=
$
show
Comments
.
html
()
$
show
Comments
.
html
prevHtml
.
replace
"Hide"
,
"Show"
$
hide
Comments
.
unbind
(
'click'
).
click
handleShowSingleThread
prevHtml
=
$
hide
Comments
.
html
()
$
hide
Comments
.
html
prevHtml
.
replace
"Hide"
,
"Show"
handleShowSingleThread
=
->
$threadTitle
=
$local
(
".thread-title"
)
...
...
@@ -269,9 +271,12 @@ initializeFollowThread = (thread) ->
rebindHideEvents
=
->
$threadTitle
.
unbind
(
'click'
).
click
handleHideSingleThread
$showComments
.
unbind
(
'click'
).
click
handleHideSingleThread
$showComments
.
removeClass
(
"discussion-show-comments"
)
.
addClass
(
"discussion-hide-comments"
)
prevHtml
=
$showComments
.
html
()
$showComments
.
html
prevHtml
.
replace
"Show"
,
"Hide"
if
$content
.
children
(
".comments"
).
length
$content
.
children
(
".comments"
).
show
()
rebindHideEvents
()
...
...
@@ -299,6 +304,9 @@ initializeFollowThread = (thread) ->
"click .discussion-show-comments"
:
->
handleShowSingleThread
(
this
)
"click .discussion-hide-comments"
:
->
handleHideSingleThread
(
this
)
"click .discussion-reply-thread"
:
->
handleShowSingleThread
(
$local
(
".thread-title"
))
handleReply
(
this
)
...
...
@@ -374,11 +382,12 @@ initializeFollowThread = (thread) ->
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
,
$contentBody
.
attr
(
"id"
)]
id
=
$content
.
attr
(
"_id"
)
discussion_id
=
$content
.
parents
(
".discussion"
).
attr
(
"_id"
)
if
$content
.
hasClass
(
"thread"
)
discussion_id
=
$content
.
attr
(
"_discussion_id"
)
permalink
=
Discussion
.
urlFor
(
"permanent_link_thread"
,
discussion_id
,
id
)
else
thread_id
=
$content
.
parents
(
".thread"
).
attr
(
"_id"
)
discussion_id
=
$content
.
parents
(
".thread"
).
attr
(
"_discussion_id"
)
permalink
=
Discussion
.
urlFor
(
"permanent_link_comment"
,
discussion_id
,
thread_id
,
id
)
$local
(
".discussion-permanent-link"
).
attr
"href"
,
permalink
...
...
lms/static/coffee/src/discussion/discussion.coffee
View file @
e5fe54ca
...
...
@@ -55,7 +55,7 @@ initializeFollowDiscussion = (discussion) ->
handleCancelNewPost
=
(
elem
)
->
if
$discussion
.
hasClass
(
"inline-discussion"
)
$local
(
".new-post-form"
).
addClass
(
"collapsed"
)
else
else
if
$discussion
.
hasClass
(
"forum-discussion"
)
$local
(
".new-post-form"
).
hide
()
handleSimilarPost
=
(
elem
)
->
...
...
@@ -106,7 +106,7 @@ initializeFollowDiscussion = (discussion) ->
if
$discussion
.
hasClass
(
"inline-discussion"
)
$input
.
bind
'focus'
,
(
e
)
->
$local
(
".new-post-form"
).
removeClass
(
'collapsed'
)
else
else
if
$discussion
.
hasClass
(
"forum-discussion"
)
$local
(
".new-post-form"
).
removeClass
(
'collapsed'
)
$local
(
".new-post-tags"
).
tagsInput
Discussion
.
tagsInputOptions
()
...
...
@@ -135,8 +135,9 @@ initializeFollowDiscussion = (discussion) ->
dataType
:
'html'
success
:
(
data
,
textStatus
)
->
$data
=
$
(
data
)
$parent
=
$discussion
.
parent
()
$discussion
.
replaceWith
(
$data
)
$discussion
=
$
(
".discussion[_id='
#{
id
}
']
"
)
$discussion
=
$
parent
.
children
(
".discussion
"
)
Discussion
.
initializeDiscussion
(
$discussion
)
Discussion
.
bindDiscussionEvents
(
$discussion
)
...
...
@@ -158,6 +159,7 @@ initializeFollowDiscussion = (discussion) ->
if
$discussion
.
hasClass
(
"inline-discussion"
)
initializeNewPost
()
if
$discussion
.
hasClass
(
"forum-discussion"
)
$discussionSidebar
=
$
(
".discussion-sidebar"
)
if
$discussionSidebar
.
length
$sidebarLocal
=
Discussion
.
generateLocal
(
$discussionSidebar
)
...
...
lms/static/coffee/src/discussion/user_profile.coffee
View file @
e5fe54ca
...
...
@@ -30,3 +30,5 @@ Discussion = @Discussion
handleUpdateModeratorStatus
(
this
,
false
)
"click .sidebar-promote-moderator-button"
:
(
event
)
->
handleUpdateModeratorStatus
(
this
,
true
)
initializeUserActiveDiscussion
:
(
$discussion
)
->
lms/static/sass/_discussion.scss
View file @
e5fe54ca
...
...
@@ -844,7 +844,7 @@ $tag-text-color: #5b614f;
}
}
&
.inline-discussion
,
.forum-discussion
{
&
.inline-discussion
,
.forum-discussion
,
.user-discussion
{
.new-post-form
{
margin
:
24px
60px
;
...
...
lms/templates/discussion/_thread.html
View file @
e5fe54ca
...
...
@@ -4,9 +4,16 @@
<
%!
from
django_comment_client
.
utils
import
pluralize
%
>
<
%!
import
urllib
%
>
<
%!
def
user_id_with_anonymity
(
content
)
:
if
content
.
get
('
anonymous
',
False
)
:
return
''
else:
return
content
['
user_id
']
%
>
<
%
def
name=
"render_thread(course_id, thread, show_comments=False)"
>
<div
class=
"thread"
_id=
"${thread['id']}"
>
<div
class=
"thread"
_id=
"${thread['id']}"
_discussion_id=
"${thread['commentable_id']}"
_author_id=
"${user_id_with_anonymity(thread)}"
>
${render_content(thread, "thread", show_comments=show_comments)}
% if show_comments:
${render_comments(thread.get('children', []))}
...
...
@@ -16,9 +23,9 @@
<
%
def
name=
"render_comment(comment)"
>
% if comment['endorsed']:
<div
class=
"comment endorsed"
_id=
"${comment['id']}"
>
<div
class=
"comment endorsed"
_id=
"${comment['id']}"
_author_id=
"${user_id_with_anonymity(comment)}"
>
% else:
<div
class=
"comment"
_id=
"${comment['id']}"
>
<div
class=
"comment"
_id=
"${comment['id']}"
_author_id=
"${user_id_with_anonymity(comment)}"
>
% endif
${render_content(comment, "comment")}
<div
class=
"comments"
>
...
...
@@ -60,7 +67,7 @@
${render_title(content, type, **kwargs)}
<div
class=
"discussion-content-view"
>
<a
name=
"${content['id']}"
></a>
<a
name=
"${content['id']}"
style=
"width: 0; height: 0; padding: 0; border: none;"
></a>
% if content.get('highlighted_body', None):
<div
class=
"content-body ${type}-body"
id=
"content-body-${content['id']}"
>
${content['highlighted_body'] | h}
</div>
% else:
...
...
@@ -103,20 +110,16 @@
<
%
def
name=
"render_bottom_bar(content, type, **kwargs)"
>
<div
class=
"info"
>
${render_info(content)}
${render_info(content
, type, **kwargs
)}
<ul
class=
"discussion-actions"
>
<li>
${render_link("discussion-link discussion-reply discussion-reply-" + type, "Reply")}
</li>
<li><div
class=
"follow-wrapper"
></div></li>
<li>
${render_link("discussion-link discussion-permanent-link", "Permanent Link")}
</li>
</ul>
</div>
</
%
def>
<
%
def
name=
"render_info(content)"
>
<
%
def
name=
"render_info(content
, type, **kwargs
)"
>
<
%
def
url_for_user
(
user_id
)
:
return
reverse
('
django_comment_client
.
forum
.
views
.
user_profile
',
args=
[course_id,
user_id
])
...
...
@@ -131,8 +134,12 @@
</div>
<div
class=
"comment-count"
>
% if content.get('comments_count', -1) >= 0:
% if kwargs.get('show_comments') is True:
<a
href=
"javascript:void(0)"
class=
"discussion-hide-comments"
>
Hide ${content['comments_count']} ${pluralize('comment', content['comments_count'])}
</a>
% else:
<a
href=
"javascript:void(0)"
class=
"discussion-show-comments"
>
Show ${content['comments_count']} ${pluralize('comment', content['comments_count'])}
</a>
% endif
% endif
</div>
</
%
def>
...
...
lms/templates/discussion/_user_active_threads.html
0 → 100644
View file @
e5fe54ca
<
%
namespace
name=
"renderer"
file=
"_thread.html"
/>
<
%!
from
django
.
template
.
defaultfilters
import
escapejs
%
>
<section
class=
"discussion user-active-discussion"
>
<div
class=
"discussion-non-content discussion-local"
></div>
<div
class=
"threads"
>
% for thread in threads:
${renderer.render_thread(course_id, thread, show_comments=True)}
% endfor
</div>
<
%
include
file=
"_paginator.html"
/>
</section>
<script
type=
"text/javascript"
>
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 | escapejs}"
));
</script>
lms/templates/discussion/user_profile.html
View file @
e5fe54ca
<
%!
from
django
.
template
.
defaultfilters
import
escapejs
%
>
<
%
namespace
name=
"renderer"
file=
"_thread.html"
/>
<
%
inherit
file=
"../main.html"
/>
<
%
namespace
name=
'static'
file=
'../static_content.html'
/>
...
...
@@ -28,7 +29,7 @@
</section>
<section
class=
"course-content"
>
${content}
</section>
</div>
</section>
...
...
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