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
71416732
Commit
71416732
authored
Jan 21, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
course_file now includes parsing.
parent
829e890a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
52 deletions
+6
-52
courseware/content_parser.py
+4
-6
courseware/views.py
+2
-46
No files found.
courseware/content_parser.py
View file @
71416732
...
...
@@ -57,13 +57,13 @@ def item(l, default="", process=lambda x:x):
raise
Exception
(
'Malformed XML'
)
def
course_file
(
user
):
# TODO: Cache.
Also, return the libxml2 object.
return
settings
.
DATA_DIR
+
UserProfile
.
objects
.
get
(
user
=
user
)
.
courseware
# TODO: Cache.
return
etree
.
parse
(
settings
.
DATA_DIR
+
UserProfile
.
objects
.
get
(
user
=
user
)
.
courseware
)
def
module_xml
(
coursefile
,
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
=
etree
.
parse
(
coursefile
)
doc
=
coursefile
# Sanitize input
if
not
module
.
isalnum
():
...
...
@@ -82,9 +82,7 @@ def module_xml(coursefile, module, id_tag, module_id):
return
etree
.
tostring
(
result_set
[
0
])
#return result_set[0].serialize()
def
toc_from_xml
(
coursefile
,
active_chapter
,
active_section
):
dom
=
etree
.
parse
(
coursefile
)
def
toc_from_xml
(
dom
,
active_chapter
,
active_section
):
name
=
dom
.
xpath
(
'//course/@name'
)[
0
]
chapters
=
dom
.
xpath
(
'//course[@name=$name]/chapter'
,
name
=
name
)
...
...
courseware/views.py
View file @
71416732
...
...
@@ -43,7 +43,7 @@ def profile(request):
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/'
)
dom
=
etree
.
parse
(
content_parser
.
course_file
(
request
.
user
)
)
dom
=
content_parser
.
course_file
(
request
.
user
)
hw
=
[]
course
=
dom
.
xpath
(
'//course/@name'
)[
0
]
chapters
=
dom
.
xpath
(
'//course[@name=$course]/chapter'
,
course
=
course
)
...
...
@@ -126,51 +126,7 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
if
course
!=
"6.002 Spring 2012"
:
return
redirect
(
'/'
)
cf
=
content_parser
.
course_file
(
request
.
user
)
dom
=
parse
(
cf
)
dom_course
=
content_parser
.
dom_select
(
dom
,
'course'
,
course
)
dom_chapter
=
content_parser
.
dom_select
(
dom_course
,
'chapter'
,
chapter
)
dom_section
=
content_parser
.
dom_select
(
dom_chapter
,
'section'
,
section
)
if
dom_section
!=
None
:
module
=
[
e
for
e
in
dom_section
.
childNodes
if
e
.
nodeType
==
1
][
0
]
else
:
module
=
None
accordion
=
render_accordion
(
request
,
course
,
chapter
,
section
)
module
=
render_module
(
request
,
module
)
if
'init_js'
not
in
module
:
module
[
'init_js'
]
=
''
context
=
{
'init'
:
accordion
[
'init_js'
]
+
module
[
'init_js'
],
'accordion'
:
accordion
[
'content'
],
'content'
:
module
[
'content'
],
'csrf'
:
csrf
(
request
)[
'csrf_token'
]}
return
render_to_response
(
'courseware.html'
,
context
)
def
index
(
request
,
course
=
"6.002 Spring 2012"
,
chapter
=
"Using the System"
,
section
=
"Hints"
):
''' Displays courseware accordion, and any associated content.
'''
if
not
settings
.
COURSEWARE_ENABLED
or
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/'
)
# Fixes URLs -- we don't get funny encoding characters from spaces
# so they remain readable
## TODO: Properly replace underscores
course
=
course
.
replace
(
"_"
,
" "
)
chapter
=
chapter
.
replace
(
"_"
,
" "
)
section
=
section
.
replace
(
"_"
,
" "
)
# HACK: Force course to 6.002 for now
# Without this, URLs break
if
course
!=
"6.002 Spring 2012"
:
return
redirect
(
'/'
)
cf
=
content_parser
.
course_file
(
request
.
user
)
dom
=
etree
.
parse
(
cf
)
dom
=
content_parser
.
course_file
(
request
.
user
)
dom_module
=
dom
.
xpath
(
"//course[@name=$course]/chapter[@name=$chapter]//section[@name=$section]/*[1]"
,
course
=
course
,
chapter
=
chapter
,
section
=
section
)
if
len
(
dom_module
)
==
0
:
...
...
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