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
591f9023
Commit
591f9023
authored
Jan 20, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Content parser moved to lxml
parent
95842602
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
17 deletions
+16
-17
courseware/content_parser.py
+16
-17
No files found.
courseware/content_parser.py
View file @
591f9023
...
@@ -4,10 +4,10 @@ try:
...
@@ -4,10 +4,10 @@ try:
except
:
except
:
settings
=
None
settings
=
None
from
xml.dom.minidom
import
parse
,
parseString
from
lxml
import
etree
from
lxml
import
etree
import
json
''' This file will eventually form an abstraction layer between the
''' This file will eventually form an abstraction layer between the
course XML file and the rest of the system.
course XML file and the rest of the system.
...
@@ -56,7 +56,6 @@ def item(l, default="", process=lambda x:x):
...
@@ -56,7 +56,6 @@ def item(l, default="", process=lambda x:x):
else
:
else
:
raise
Exception
(
'Malformed XML'
)
raise
Exception
(
'Malformed XML'
)
def
course_file
(
user
):
def
course_file
(
user
):
# TODO: Cache. Also, return the libxml2 object.
# TODO: Cache. Also, return the libxml2 object.
return
settings
.
DATA_DIR
+
UserProfile
.
objects
.
get
(
user
=
user
)
.
courseware
return
settings
.
DATA_DIR
+
UserProfile
.
objects
.
get
(
user
=
user
)
.
courseware
...
@@ -84,26 +83,26 @@ def module_xml(coursefile, module, id_tag, module_id):
...
@@ -84,26 +83,26 @@ def module_xml(coursefile, module, id_tag, module_id):
#return result_set[0].serialize()
#return result_set[0].serialize()
def
toc_from_xml
(
coursefile
,
active_chapter
,
active_section
):
def
toc_from_xml
(
coursefile
,
active_chapter
,
active_section
):
dom
=
parse
(
coursefile
)
dom2
=
etree
.
parse
(
coursefile
)
name
=
dom2
.
xpath
(
'//course/@name'
)[
0
]
course
=
dom
.
getElementsByTagName
(
'course'
)[
0
]
chapters
=
dom2
.
xpath
(
'//course[@name=$name]/chapter'
,
name
=
name
)
name
=
course
.
getAttribute
(
"name"
)
chapters
=
course
.
getElementsByTagName
(
'chapter'
)
ch
=
list
()
ch
=
list
()
for
c
in
chapters
:
for
c
in
chapters
:
if
c
.
get
Attribute
(
"name"
)
==
'hidden'
:
if
c
.
get
(
'name'
)
==
'hidden'
:
continue
continue
sections
=
list
()
sections
=
list
()
for
s
in
c
.
getElementsByTagName
(
'section'
):
for
s
in
dom2
.
xpath
(
'//course[@name=$name]/chapter[@name=$chname]/section'
,
name
=
name
,
chname
=
c
.
get
(
'name'
)):
sections
.
append
({
'name'
:
s
.
get
Attribute
(
"name"
)
,
sections
.
append
({
'name'
:
s
.
get
(
"name"
)
or
""
,
'time'
:
s
.
get
Attribute
(
"time"
)
,
'time'
:
s
.
get
(
"time"
)
or
""
,
'format'
:
s
.
get
Attribute
(
"format"
)
,
'format'
:
s
.
get
(
"format"
)
or
""
,
'due'
:
s
.
get
Attribute
(
"due"
)
,
'due'
:
s
.
get
(
"due"
)
or
""
,
'active'
:(
c
.
get
Attribute
(
"name"
)
==
active_chapter
and
\
'active'
:(
c
.
get
(
"name"
)
==
active_chapter
and
\
s
.
get
Attribute
(
"name"
)
==
active_section
)})
s
.
get
(
"name"
)
==
active_section
)})
ch
.
append
({
'name'
:
c
.
get
Attribute
(
"name"
),
ch
.
append
({
'name'
:
c
.
get
(
"name"
),
'sections'
:
sections
,
'sections'
:
sections
,
'active'
:(
c
.
get
Attribute
(
"name"
)
==
active_chapter
)})
'active'
:(
c
.
get
(
"name"
)
==
active_chapter
)})
return
ch
return
ch
def
dom_select
(
dom
,
element_type
,
element_name
):
def
dom_select
(
dom
,
element_type
,
element_name
):
...
...
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