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
4569ee9d
Commit
4569ee9d
authored
Dec 19, 2013
by
Brian Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add options to dump_course_structure to output inherited metadata.
parent
1c979090
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
6 deletions
+38
-6
lms/djangoapps/courseware/management/commands/dump_course_structure.py
+38
-6
No files found.
lms/djangoapps/courseware/management/commands/dump_course_structure.py
View file @
4569ee9d
...
...
@@ -23,10 +23,11 @@ from textwrap import dedent
from
django.core.management.base
import
BaseCommand
,
CommandError
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.inheritance
import
own_metadata
from
xmodule.modulestore.inheritance
import
own_metadata
,
compute_inherited_metadata
from
xblock.fields
import
Scope
FILTER_LIST
=
[
'xml_attributes'
,
'checklists'
]
INHERITED_FILTER_LIST
=
[
'children'
,
'xml_attributes'
,
'checklists'
]
class
Command
(
BaseCommand
):
...
...
@@ -41,6 +42,14 @@ class Command(BaseCommand):
action
=
'store'
,
default
=
'default'
,
help
=
'Name of the modulestore'
),
make_option
(
'--inherited'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Whether to include inherited metadata'
),
make_option
(
'--inherited_defaults'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Whether to include default values of inherited metadata'
),
)
def
handle
(
self
,
*
args
,
**
options
):
...
...
@@ -62,14 +71,18 @@ class Command(BaseCommand):
if
course
is
None
:
raise
CommandError
(
"Invalid course_id"
)
# precompute inherited metadata at the course level, if needed:
if
options
[
'inherited'
]:
compute_inherited_metadata
(
course
)
# Convert course data to dictionary and dump it as JSON to stdout
info
=
dump_module
(
course
)
info
=
dump_module
(
course
,
inherited
=
options
[
'inherited'
],
defaults
=
options
[
'inherited_defaults'
]
)
return
json
.
dumps
(
info
,
indent
=
2
,
sort_keys
=
True
)
def
dump_module
(
module
,
destination
=
None
):
def
dump_module
(
module
,
destination
=
None
,
inherited
=
False
,
defaults
=
False
):
"""
Add the module and all its children to the destination dictionary in
as a flat structure.
...
...
@@ -83,10 +96,29 @@ def dump_module(module, destination=None):
destination
[
module
.
location
.
url
()]
=
{
'category'
:
module
.
location
.
category
,
'children'
:
module
.
children
if
hasattr
(
module
,
'children'
)
else
[],
'metadata'
:
filtered_metadata
'metadata'
:
filtered_metadata
,
}
if
inherited
:
# when calculating inherited metadata, don't include existing
# locally-defined metadata
inherited_metadata_filter_list
=
list
(
filtered_metadata
.
keys
())
inherited_metadata_filter_list
.
extend
(
INHERITED_FILTER_LIST
)
def
is_inherited
(
field
):
if
field
.
name
in
inherited_metadata_filter_list
:
return
False
elif
field
.
scope
!=
Scope
.
settings
:
return
False
elif
defaults
==
True
:
return
True
else
:
return
field
.
values
!=
field
.
default
inherited_metadata
=
{
field
.
name
:
field
.
read_json
(
module
)
for
field
in
module
.
fields
.
values
()
if
is_inherited
(
field
)}
destination
[
module
.
location
.
url
()][
'inherited_metadata'
]
=
inherited_metadata
for
child
in
module
.
get_children
():
dump_module
(
child
,
destination
)
dump_module
(
child
,
destination
,
inherited
,
defaults
)
return
destination
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