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
8d9f9e74
Commit
8d9f9e74
authored
Sep 13, 2012
by
Arjun Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix courseware context links; filter out unstarted topics.
parent
0ea9e432
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
28 deletions
+75
-28
lms/djangoapps/django_comment_client/forum/views.py
+3
-7
lms/djangoapps/django_comment_client/utils.py
+70
-19
lms/templates/discussion/_underscore_templates.html
+2
-2
No files found.
lms/djangoapps/django_comment_client/forum/views.py
View file @
8d9f9e74
...
...
@@ -79,8 +79,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs):
for
thread
in
threads
:
courseware_context
=
get_courseware_context
(
thread
,
course
)
if
courseware_context
:
thread
[
'courseware_location'
]
=
courseware_context
[
'courseware_location'
]
thread
[
'courseware_title'
]
=
courseware_context
[
'courseware_title'
]
thread
.
update
(
courseware_context
)
context
=
{
'threads'
:
map
(
utils
.
safe_content
,
threads
),
...
...
@@ -199,8 +198,7 @@ def forum_form_discussion(request, course_id):
for
thread
in
threads
:
courseware_context
=
get_courseware_context
(
thread
,
course
)
if
courseware_context
:
thread
[
'courseware_location'
]
=
courseware_context
[
'courseware_location'
]
thread
[
'courseware_title'
]
=
courseware_context
[
'courseware_title'
]
thread
.
update
(
courseware_context
)
if
request
.
is_ajax
():
return
utils
.
JsonResponse
({
'discussion_data'
:
threads
,
# TODO: Standardize on 'discussion_data' vs 'threads'
...
...
@@ -273,8 +271,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
for
thread
in
threads
:
courseware_context
=
get_courseware_context
(
thread
,
course
)
if
courseware_context
:
thread
[
'courseware_location'
]
=
courseware_context
[
'courseware_location'
]
thread
[
'courseware_title'
]
=
courseware_context
[
'courseware_title'
]
thread
.
update
(
courseware_context
)
threads
=
[
utils
.
safe_content
(
thread
)
for
thread
in
threads
]
...
...
@@ -290,7 +287,6 @@ def single_thread(request, course_id, discussion_id, thread_id):
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
)
...
...
lms/djangoapps/django_comment_client/utils.py
View file @
8d9f9e74
import
time
from
collections
import
defaultdict
from
importlib
import
import_module
from
courseware.models
import
StudentModuleCache
from
courseware.module_render
import
get_module
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.search
import
path_to_location
from
django.http
import
HttpResponse
from
django.utils
import
simplejson
from
django.db
import
connection
...
...
@@ -74,7 +77,44 @@ def get_discussion_category_map(course):
global
_DISCUSSIONINFO
if
not
_DISCUSSIONINFO
:
initialize_discussion_info
(
course
)
return
_DISCUSSIONINFO
[
'category_map'
]
return
filter_unstarted_categories
(
_DISCUSSIONINFO
[
'category_map'
])
def
filter_unstarted_categories
(
category_map
):
now
=
time
.
gmtime
()
result_map
=
{}
unfiltered_queue
=
[
category_map
]
filtered_queue
=
[
result_map
]
while
len
(
unfiltered_queue
)
>
0
:
unfiltered_map
=
unfiltered_queue
.
pop
()
filtered_map
=
filtered_queue
.
pop
()
filtered_map
[
"children"
]
=
[]
filtered_map
[
"entries"
]
=
{}
filtered_map
[
"subcategories"
]
=
{}
for
child
in
unfiltered_map
[
"children"
]:
if
child
in
unfiltered_map
[
"entries"
]:
if
unfiltered_map
[
"entries"
][
child
][
"start_date"
]
<
now
:
filtered_map
[
"children"
]
.
append
(
child
)
filtered_map
[
"entries"
][
child
]
=
{}
for
key
in
unfiltered_map
[
"entries"
][
child
]:
if
key
!=
"start_date"
:
filtered_map
[
"entries"
][
child
][
key
]
=
unfiltered_map
[
"entries"
][
child
][
key
]
else
:
print
"filtering
%
s"
%
child
,
unfiltered_map
[
"entries"
][
child
][
"start_date"
]
else
:
if
unfiltered_map
[
"subcategories"
][
child
][
"start_date"
]
<
now
:
filtered_map
[
"children"
]
.
append
(
child
)
filtered_map
[
"subcategories"
][
child
]
=
{}
unfiltered_queue
.
append
(
unfiltered_map
[
"subcategories"
][
child
])
filtered_queue
.
append
(
filtered_map
[
"subcategories"
][
child
])
return
result_map
def
sort_map_entries
(
category_map
):
things
=
[]
...
...
@@ -109,32 +149,49 @@ def initialize_discussion_info(course):
discussion_id_map
[
id
]
=
{
"location"
:
location
,
"title"
:
title
}
category
=
" / "
.
join
([
x
.
strip
()
for
x
in
category
.
split
(
"/"
)])
unexpanded_category_map
[
category
]
.
append
({
"title"
:
title
,
"id"
:
id
,
"sort_key"
:
sort_key
})
"sort_key"
:
sort_key
,
"start_date"
:
module
.
start
})
category_map
=
{
"entries"
:
defaultdict
(
dict
),
"subcategories"
:
defaultdict
(
dict
)}
for
category_path
,
entries
in
unexpanded_category_map
.
items
():
node
=
category_map
[
"subcategories"
]
path
=
[
x
.
strip
()
for
x
in
category_path
.
split
(
"/"
)]
# Find the earliest start date for the entries in this category
category_start_date
=
None
for
entry
in
entries
:
if
category_start_date
is
None
or
entry
[
"start_date"
]
<
category_start_date
:
category_start_date
=
entry
[
"start_date"
]
for
level
in
path
[:
-
1
]:
if
level
not
in
node
:
node
[
level
]
=
{
"subcategories"
:
defaultdict
(
dict
),
"entries"
:
defaultdict
(
dict
),
"sort_key"
:
level
}
"sort_key"
:
level
,
"start_date"
:
category_start_date
}
else
:
if
node
[
level
][
"start_date"
]
>
category_start_date
:
node
[
level
][
"start_date"
]
=
category_start_date
node
=
node
[
level
][
"subcategories"
]
level
=
path
[
-
1
]
if
level
not
in
node
:
node
[
level
]
=
{
"subcategories"
:
defaultdict
(
dict
),
"entries"
:
defaultdict
(
dict
),
"sort_key"
:
level
}
"sort_key"
:
level
,
"start_date"
:
category_start_date
}
else
:
if
node
[
level
][
"start_date"
]
>
category_start_date
:
node
[
level
][
"start_date"
]
=
category_start_date
for
entry
in
entries
:
node
[
level
][
"entries"
][
entry
[
"title"
]]
=
{
"id"
:
entry
[
"id"
],
"sort_key"
:
entry
[
"sort_key"
]}
"sort_key"
:
entry
[
"sort_key"
],
"start_date"
:
entry
[
"start_date"
]}
for
topic
,
entry
in
course
.
metadata
.
get
(
'discussion_topics'
,
{})
.
items
():
category_map
[
'entries'
][
topic
]
=
{
"id"
:
entry
[
"id"
],
"sort_key"
:
entry
.
get
(
"sort_key"
,
topic
)
}
"sort_key"
:
entry
.
get
(
"sort_key"
,
topic
)
,
"start_date"
:
time
.
gmtime
()}
sort_map_entries
(
category_map
)
_DISCUSSIONINFO
=
{}
...
...
@@ -142,16 +199,6 @@ def initialize_discussion_info(course):
_DISCUSSIONINFO
[
'id_map'
]
=
discussion_id_map
_DISCUSSIONINFO
[
'category_map'
]
=
category_map
def
get_courseware_context
(
content
,
course
):
id_map
=
get_discussion_id_map
(
course
)
id
=
content
[
'commentable_id'
]
content_info
=
None
if
id
in
id_map
:
location
=
id_map
[
id
][
"location"
]
.
url
()
title
=
id_map
[
id
][
"title"
]
content_info
=
{
"courseware_location"
:
location
,
"courseware_title"
:
title
}
return
content_info
class
JsonResponse
(
HttpResponse
):
def
__init__
(
self
,
data
=
None
):
content
=
simplejson
.
dumps
(
data
)
...
...
@@ -270,10 +317,14 @@ def get_courseware_context(content, course):
if
id
in
id_map
:
location
=
id_map
[
id
][
"location"
]
.
url
()
title
=
id_map
[
id
][
"title"
]
content_info
=
{
"courseware_location"
:
location
,
"courseware_title"
:
title
}
(
course_id
,
chapter
,
section
,
position
)
=
path_to_location
(
modulestore
(),
course
.
id
,
location
)
url
=
reverse
(
'courseware_position'
,
kwargs
=
{
"course_id"
:
course_id
,
"chapter"
:
chapter
,
"section"
:
section
,
"position"
:
position
})
content_info
=
{
"courseware_url"
:
url
,
"courseware_title"
:
title
}
return
content_info
def
safe_content
(
content
):
fields
=
[
'id'
,
'title'
,
'body'
,
'course_id'
,
'anonymous'
,
'endorsed'
,
...
...
lms/templates/discussion/_underscore_templates.html
View file @
8d9f9e74
...
...
@@ -39,9 +39,9 @@
<
div
class
=
"post-body"
>
$
{
'<%- body %>'
}
<
/div
>
$
{
'<% if (obj.courseware_
location
) { %>'
}
$
{
'<% if (obj.courseware_
url
) { %>'
}
<
div
class
=
"post-context"
>
(
this
post
is
about
<
a
href
=
"
../../jump_to/${'<%- courseware_location
%>'}"
>
$
{
'<%- courseware_title %>'
}
<
/a>
)
(
this
post
is
about
<
a
href
=
"
${'<%- courseware_url
%>'}"
>
$
{
'<%- courseware_title %>'
}
<
/a>
)
<
/div
>
$
{
'<% } %>'
}
...
...
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