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
c8f261ef
Commit
c8f261ef
authored
Mar 09, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work-around for not finding XML for sections in section files. Note: Requires data push
parent
f8e70639
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
courseware/content_parser.py
+24
-7
courseware/module_render.py
+1
-1
No files found.
courseware/content_parser.py
View file @
c8f261ef
...
...
@@ -3,6 +3,7 @@ import json
import
logging
import
os
import
re
import
sys
from
datetime
import
timedelta
from
lxml
import
etree
...
...
@@ -22,6 +23,9 @@ course XML file and the rest of the system.
TODO: Shift everything from xml.dom.minidom to XPath (or XQuery)
'''
class
ContentException
(
Exception
):
pass
log
=
logging
.
getLogger
(
"mitx.courseware"
)
...
...
@@ -207,21 +211,34 @@ def section_file(user, section):
return
tree
def
module_xml
(
coursefile
,
module
,
id_tag
,
module_id
):
def
module_xml
(
user
,
module
,
id_tag
,
module_id
):
''' Get XML for a module based on module and module_id. Assumes
module occurs once in courseware XML file.. '''
doc
=
coursefile
module occurs once in courseware XML file or hidden section. '''
# Sanitize input
if
not
module
.
isalnum
():
raise
Exception
(
"Module is not alphanumeric"
)
if
not
module_id
.
isalnum
():
raise
Exception
(
"Module ID is not alphanumeric"
)
xpath_search
=
'//*/{module}[(@{id_tag} = "{id}") or (@id = "{id}")]'
.
format
(
module
=
module
,
id_tag
=
id_tag
,
id
=
module_id
)
# Generate search
xpath_search
=
'//{module}[(@{id_tag} = "{id}") or (@id = "{id}")]'
.
format
(
module
=
module
,
id_tag
=
id_tag
,
id
=
module_id
)
#result_set=doc.xpathEval(xpath_search)
doc
=
course_file
(
user
)
section_list
=
(
s
[:
-
4
]
for
s
in
os
.
listdir
(
settings
.
DATA_DIR
+
'/sections'
)
if
s
[
-
4
:]
==
'.xml'
)
result_set
=
doc
.
xpath
(
xpath_search
)
if
len
(
result_set
)
<
1
:
for
section
in
section_list
:
try
:
s
=
section_file
(
user
,
section
)
except
etree
.
XMLSyntaxError
:
ex
=
sys
.
exc_info
()
raise
ContentException
(
"Malformed XML in "
+
section
+
"("
+
str
(
ex
[
1
]
.
msg
)
+
")"
)
result_set
=
s
.
xpath
(
xpath_search
)
if
len
(
result_set
)
!=
0
:
break
if
len
(
result_set
)
>
1
:
print
"WARNING: Potentially malformed course file"
,
module
,
module_id
if
len
(
result_set
)
==
0
:
...
...
courseware/module_render.py
View file @
c8f261ef
...
...
@@ -67,7 +67,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
ajax_url
=
'/modx/'
+
module
+
'/'
+
id
+
'/'
# Grab the XML corresponding to the request from course.xml
xml
=
content_parser
.
module_xml
(
content_parser
.
course_file
(
request
.
user
)
,
module
,
'id'
,
id
)
xml
=
content_parser
.
module_xml
(
request
.
user
,
module
,
'id'
,
id
)
# Create the module
instance
=
courseware
.
modules
.
get_module_class
(
module
)(
xml
,
...
...
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