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
74b789b6
Commit
74b789b6
authored
Feb 06, 2017
by
Brian Jacobel
Committed by
Diana Huang
Mar 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get the block tree and display it on the outline page
parent
7862e375
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletions
+46
-1
lms/djangoapps/courseware/views/views.py
+30
-0
lms/templates/courseware/course-outline.html
+16
-1
No files found.
lms/djangoapps/courseware/views/views.py
View file @
74b789b6
...
...
@@ -45,6 +45,7 @@ from lms.djangoapps.grades.new.course_grade import CourseGradeFactory
from
lms.djangoapps.instructor.enrollment
import
uses_shib
from
lms.djangoapps.verify_student.models
import
SoftwareSecurePhotoVerification
from
lms.djangoapps.ccx.custom_exception
import
CCXLocatorValidationException
from
lms.djangoapps.course_api.blocks.api
import
get_blocks
import
shoppingcart
import
survey.utils
...
...
@@ -1664,15 +1665,44 @@ class CourseOutlineFragmentView(FragmentView):
Course outline fragment to be shown in the unified course view.
"""
def
populate_children
(
self
,
block
,
all_blocks
):
"""
For a passed block, replace each id in its children array with the full representation of that child,
which will be looked up by id in the passed all_blocks dict.
Recursively do the same replacement for children of those children.
"""
children
=
block
.
get
(
'children'
)
or
[]
for
i
in
range
(
len
(
children
)):
child_id
=
block
[
'children'
][
i
]
child_detail
=
self
.
populate_children
(
all_blocks
[
child_id
],
all_blocks
)
block
[
'children'
][
i
]
=
child_detail
return
block
def
render_fragment
(
self
,
request
,
course_id
=
None
):
"""
Renders the course outline as a fragment.
"""
course_key
=
CourseKey
.
from_string
(
course_id
)
course
=
get_course_with_access
(
request
.
user
,
'load'
,
course_key
,
check_if_enrolled
=
True
)
course_usage_key
=
modulestore
()
.
make_course_usage_key
(
course_key
)
all_blocks
=
get_blocks
(
request
,
course_usage_key
,
user
=
request
.
user
,
nav_depth
=
3
,
requested_fields
=
[
'children'
,
'display_name'
,
'type'
],
block_types_filter
=
[
'course'
,
'chapter'
,
'vertical'
,
'sequential'
]
)
course_block_tree
=
all_blocks
[
'blocks'
][
all_blocks
[
'root'
]]
# Get the root of the block tree
context
=
{
'csrf'
:
csrf
(
request
)[
'csrf_token'
],
'course'
:
course
,
# Recurse through the block tree, fleshing out each child object
'blocks'
:
self
.
populate_children
(
course_block_tree
,
all_blocks
[
'blocks'
])
}
html
=
render_to_string
(
'courseware/course-outline.html'
,
context
)
return
Fragment
(
html
)
lms/templates/courseware/course-outline.html
View file @
74b789b6
...
...
@@ -4,9 +4,24 @@
<
%!
import
json
import
pprint
from
django
.
utils
.
translation
import
ugettext
as
_
%
>
<section
class=
"course-outline"
id=
"course-outline"
>
<p>
Hello, world!
</p>
<ul>
% for unit in blocks.get('children') or []:
<li>
${ unit['display_name'] }
</li>
<ul>
% for section in unit.get('children') or []:
<li>
${ section['display_name'] }
</li>
<ul>
% for subsection in section.get('children') or []:
<li>
${ subsection['display_name'] }
</li>
% endfor
</ul>
% endfor
</ul>
% endfor
</ul>
</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