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
a2c03fec
Commit
a2c03fec
authored
Mar 01, 2013
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make parsing more robust
parent
7a8e43a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
12 deletions
+26
-12
cms/djangoapps/contentstore/views.py
+26
-12
No files found.
cms/djangoapps/contentstore/views.py
View file @
a2c03fec
from
util.json_request
import
expect_json
from
util.json_request
import
expect_json
import
json
import
json
import
ast
import
logging
import
logging
import
os
import
os
import
sys
import
sys
...
@@ -70,7 +71,7 @@ COMPONENT_TYPES = ['customtag', 'discussion', 'html', 'problem', 'video']
...
@@ -70,7 +71,7 @@ COMPONENT_TYPES = ['customtag', 'discussion', 'html', 'problem', 'video']
ADVANCED_COMPONENT_TYPES
=
{
ADVANCED_COMPONENT_TYPES
=
{
'openended'
:
[
'combinedopenended'
,
'peergrading'
],
'openended'
:
[
'combinedopenended'
,
'peergrading'
],
'advanced'
:
[
'annotation'
]
'advanced'
:
[
'annotation'
]
,
}
}
ADVANCED_COMPONENT_POLICY_KEY
=
'advanced_modules'
ADVANCED_COMPONENT_POLICY_KEY
=
'advanced_modules'
...
@@ -289,32 +290,45 @@ def edit_unit(request, location):
...
@@ -289,32 +290,45 @@ def edit_unit(request, location):
component_templates
=
defaultdict
(
list
)
component_templates
=
defaultdict
(
list
)
# check if there are any advanced modules specified in the course policy
# check if there are any advanced modules specified in the course policy
advanced_component_types
=
ADVANCED_COMPONENT_TYPES
course_metadata
=
CourseMetadata
.
fetch
(
course
.
location
)
course_metadata
=
CourseMetadata
.
fetch
(
course
.
location
)
course_advanced_keys
=
course_metadata
.
get
(
ADVANCED_COMPONENT_POLICY_KEY
,
{})
course_advanced_keys
=
course_metadata
.
get
(
ADVANCED_COMPONENT_POLICY_KEY
,
[])
#First try to parse with json
try
:
try
:
course_advanced_keys
=
json
.
loads
(
course_advanced_keys
)
course_advanced_keys
=
json
.
loads
(
course_advanced_keys
)
except
:
except
:
log
.
error
(
"Cannot json decode course advanced policy: {0}"
.
format
(
course_advanced_keys
))
log
.
error
(
"Cannot json decode course advanced policy: {0}"
.
format
(
course_advanced_keys
))
#It may be that it is not a json object, but can be evaluated as a python literal
if
isinstance
(
course_advanced_keys
,
dict
):
try
:
advanced_component_types
.
update
(
course_advanced_keys
)
#This is a safe evaluation. See docs for ast
course_advanced_keys
=
ast
.
literal_eval
(
course_advanced_keys
)
except
:
log
.
error
(
"Cannot parse course advanced policy at all: {0}"
.
format
(
course_advanced_keys
))
course_advanced_keys
=
[]
#Set component types according to course policy file
component_types
=
COMPONENT_TYPES
if
isinstance
(
course_advanced_keys
,
list
):
#Generate a subset of the dictionary for just needed keys
course_advanced_keys
=
[
c
for
c
in
course_advanced_keys
if
c
in
ADVANCED_COMPONENT_TYPES
]
advanced_component_type_mappings
=
{
k
:
ADVANCED_COMPONENT_TYPES
.
get
(
k
,[])
for
k
in
course_advanced_keys
}
#Let course staff defined keys be valid
component_types
+=
course_advanced_keys
else
:
else
:
log
.
error
(
"Improper format for course advanced keys! {0}"
.
format
(
course_advanced_keys
))
log
.
error
(
"Improper format for course advanced keys! {0}"
.
format
(
course_advanced_keys
))
templates
=
modulestore
()
.
get_items
(
Location
(
'i4x'
,
'edx'
,
'templates'
))
templates
=
modulestore
()
.
get_items
(
Location
(
'i4x'
,
'edx'
,
'templates'
))
for
template
in
templates
:
for
template
in
templates
:
category
=
template
.
location
.
category
category
=
template
.
location
.
category
log
.
debug
(
category
)
#Map subcategory to upper level category
for
key
in
ADVANCED_COMPONENT_TYPES
:
for
key
in
course_advanced_keys
:
if
category
in
ADVANCED_COMPONENT_TYPES
[
key
]:
if
category
in
advanced_component_type_mappings
[
key
]:
category
=
key
category
=
key
break
break
if
category
in
COMPONENT_TYPES
:
if
category
in
component_types
:
#This is a hack to create categories for different xmodules
#This is a hack to create categories for different xmodules
component_templates
[
template
.
location
.
category
]
.
append
((
component_templates
[
category
]
.
append
((
template
.
display_name
,
template
.
display_name
,
template
.
location
.
url
(),
template
.
location
.
url
(),
'markdown'
in
template
.
metadata
,
'markdown'
in
template
.
metadata
,
...
...
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