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
bd05dc0b
Commit
bd05dc0b
authored
Jun 17, 2015
by
John Eskew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap course structure generation task in bulk operation.
parent
843c073f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
30 deletions
+32
-30
openedx/core/djangoapps/content/course_structures/tasks.py
+32
-30
No files found.
openedx/core/djangoapps/content/course_structures/tasks.py
View file @
bd05dc0b
...
@@ -13,38 +13,40 @@ def _generate_course_structure(course_key):
...
@@ -13,38 +13,40 @@ def _generate_course_structure(course_key):
"""
"""
Generates a course structure dictionary for the specified course.
Generates a course structure dictionary for the specified course.
"""
"""
course
=
modulestore
()
.
get_course
(
course_key
,
depth
=
None
)
with
modulestore
()
.
bulk_operations
(
course_key
):
blocks_stack
=
[
course
]
course
=
modulestore
()
.
get_course
(
course_key
,
depth
=
None
)
blocks_dict
=
{}
blocks_stack
=
[
course
]
while
blocks_stack
:
blocks_dict
=
{}
curr_block
=
blocks_stack
.
pop
()
while
blocks_stack
:
children
=
curr_block
.
get_children
()
if
curr_block
.
has_children
else
[]
curr_block
=
blocks_stack
.
pop
()
key
=
unicode
(
curr_block
.
scope_ids
.
usage_id
)
children
=
curr_block
.
get_children
()
if
curr_block
.
has_children
else
[]
block
=
{
key
=
unicode
(
curr_block
.
scope_ids
.
usage_id
)
"usage_key"
:
key
,
block
=
{
"block_type"
:
curr_block
.
category
,
"usage_key"
:
key
,
"display_name"
:
curr_block
.
display_name
,
"block_type"
:
curr_block
.
category
,
"children"
:
[
unicode
(
child
.
scope_ids
.
usage_id
)
for
child
in
children
]
"display_name"
:
curr_block
.
display_name
,
"children"
:
[
unicode
(
child
.
scope_ids
.
usage_id
)
for
child
in
children
]
}
# Retrieve these attributes separately so that we can fail gracefully
# if the block doesn't have the attribute.
attrs
=
((
'graded'
,
False
),
(
'format'
,
None
))
for
attr
,
default
in
attrs
:
if
hasattr
(
curr_block
,
attr
):
block
[
attr
]
=
getattr
(
curr_block
,
attr
,
default
)
else
:
log
.
warning
(
'Failed to retrieve
%
s attribute of block
%
s. Defaulting to
%
s.'
,
attr
,
key
,
default
)
block
[
attr
]
=
default
blocks_dict
[
key
]
=
block
# Add this blocks children to the stack so that we can traverse them as well.
blocks_stack
.
extend
(
children
)
return
{
"root"
:
unicode
(
course
.
scope_ids
.
usage_id
),
"blocks"
:
blocks_dict
}
}
# Retrieve these attributes separately so that we can fail gracefully if the block doesn't have the attribute.
attrs
=
((
'graded'
,
False
),
(
'format'
,
None
))
for
attr
,
default
in
attrs
:
if
hasattr
(
curr_block
,
attr
):
block
[
attr
]
=
getattr
(
curr_block
,
attr
,
default
)
else
:
log
.
warning
(
'Failed to retrieve
%
s attribute of block
%
s. Defaulting to
%
s.'
,
attr
,
key
,
default
)
block
[
attr
]
=
default
blocks_dict
[
key
]
=
block
# Add this blocks children to the stack so that we can traverse them as well.
blocks_stack
.
extend
(
children
)
return
{
"root"
:
unicode
(
course
.
scope_ids
.
usage_id
),
"blocks"
:
blocks_dict
}
@task
(
name
=
u'openedx.core.djangoapps.content.course_structures.tasks.update_course_structure'
)
@task
(
name
=
u'openedx.core.djangoapps.content.course_structures.tasks.update_course_structure'
)
def
update_course_structure
(
course_key
):
def
update_course_structure
(
course_key
):
...
...
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