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
d410d829
Commit
d410d829
authored
Jan 21, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All elements in course file include IDs
parent
71416732
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
1 deletions
+29
-1
courseware/content_parser.py
+29
-1
No files found.
courseware/content_parser.py
View file @
d410d829
...
...
@@ -7,6 +7,7 @@ except:
from
lxml
import
etree
import
json
import
hashlib
''' This file will eventually form an abstraction layer between the
course XML file and the rest of the system.
...
...
@@ -14,6 +15,11 @@ course XML file and the rest of the system.
TODO: Shift everything from xml.dom.minidom to XPath (or XQuery)
'''
def
fasthash
(
string
):
m
=
hashlib
.
new
(
"md4"
)
m
.
update
(
string
)
return
m
.
hexdigest
()
def
xpath
(
xml
,
query_string
,
**
args
):
''' Safe xpath query into an xml tree:
* xml is the tree.
...
...
@@ -55,10 +61,32 @@ def item(l, default="", process=lambda x:x):
return
process
(
l
[
0
])
else
:
raise
Exception
(
'Malformed XML'
)
def
id_tag
(
course
):
''' Tag all course elements with unique IDs '''
default_ids
=
{
'video'
:
'youtube'
,
'problem'
:
'filename'
,
'sequential'
:
'id'
,
'html'
:
'filename'
,
'vertical'
:
'id'
,
'tab'
:
'id'
,
'schematic'
:
'id'
}
# Tag elements with unique IDs
elements
=
course
.
xpath
(
"|"
.
join
([
'//'
+
c
for
c
in
default_ids
]))
for
elem
in
elements
:
if
elem
.
get
(
'id'
):
pass
elif
elem
.
get
(
default_ids
[
elem
.
tag
]):
elem
.
set
(
'id'
,
elem
.
get
(
default_ids
[
elem
.
tag
]))
else
:
elem
.
set
(
'id'
,
fasthash
(
etree
.
tostring
(
elem
)))
def
course_file
(
user
):
# TODO: Cache.
return
etree
.
parse
(
settings
.
DATA_DIR
+
UserProfile
.
objects
.
get
(
user
=
user
)
.
courseware
)
tree
=
etree
.
parse
(
settings
.
DATA_DIR
+
UserProfile
.
objects
.
get
(
user
=
user
)
.
courseware
)
id_tag
(
tree
)
return
tree
def
module_xml
(
coursefile
,
module
,
id_tag
,
module_id
):
''' Get XML for a module based on module and module_id. Assumes
...
...
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