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
fccfbb7d
Commit
fccfbb7d
authored
Dec 29, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Textbook browser
parent
a30f1a1e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
1 deletions
+27
-1
courseware/capa_module.py
+1
-1
courseware/content_parser.py
+24
-0
settings.py
+1
-0
urls.py
+1
-0
No files found.
courseware/capa_module.py
View file @
fccfbb7d
...
@@ -115,7 +115,7 @@ class LoncapaModule(XModule):
...
@@ -115,7 +115,7 @@ class LoncapaModule(XModule):
dom2
=
etree
.
fromstring
(
xml
)
dom2
=
etree
.
fromstring
(
xml
)
self
.
explanation
=
content_parser
.
item
(
dom2
.
xpath
(
'/problem/@explain'
))
self
.
explanation
=
content_parser
.
item
(
dom2
.
xpath
(
'/problem/@explain'
)
,
default
=
"closed"
)
self
.
explain_available
=
content_parser
.
item
(
dom2
.
xpath
(
'/problem/@explain_available'
))
self
.
explain_available
=
content_parser
.
item
(
dom2
.
xpath
(
'/problem/@explain_available'
))
self
.
due_date
=
content_parser
.
item
(
dom2
.
xpath
(
'/problem/@due'
))
self
.
due_date
=
content_parser
.
item
(
dom2
.
xpath
(
'/problem/@due'
))
...
...
courseware/content_parser.py
View file @
fccfbb7d
...
@@ -11,6 +11,30 @@ course XML file and the rest of the system.
...
@@ -11,6 +11,30 @@ course XML file and the rest of the system.
TODO: Shift everything from xml.dom.minidom to XPath (or XQuery)
TODO: Shift everything from xml.dom.minidom to XPath (or XQuery)
'''
'''
def
xpath
(
xml
,
query_string
,
**
args
):
''' Safe xpath query into an xml tree:
* xml is the tree.
* query_string is the query
* args are the parameters. Substitute for {params}. '''
doc
=
etree
.
fromstring
(
xml
)
print
type
(
doc
)
def
escape
(
x
):
# TODO: This should escape the string. For now, we just assume it's made of valid characters.
# Couldn't figure out how to escape for lxml in a few quick Googles
valid_chars
=
""
.
join
(
map
(
chr
,
range
(
ord
(
'a'
),
ord
(
'z'
)
+
1
)
+
range
(
ord
(
'A'
),
ord
(
'Z'
)
+
1
)
+
range
(
ord
(
'0'
),
ord
(
'9'
)
+
1
)))
+
"_ "
for
e
in
x
:
if
e
not
in
valid_chars
:
raise
Exception
(
"Invalid char in xpath expression. TODO: Escape"
)
return
x
args
=
dict
(
((
k
,
escape
(
args
[
k
]))
for
k
in
args
)
)
print
args
results
=
doc
.
xpath
(
query_string
.
format
(
**
args
))
return
results
if
__name__
==
'__main__'
:
print
xpath
(
'<html><problem name="Bob"></problem></html>'
,
'/{search}/problem[@name="{name}"]'
,
search
=
'html'
,
name
=
"Bob"
)
def
item
(
l
,
default
=
""
,
process
=
lambda
x
:
x
):
def
item
(
l
,
default
=
""
,
process
=
lambda
x
:
x
):
if
len
(
l
)
==
0
:
if
len
(
l
)
==
0
:
return
default
return
default
...
...
settings.py
View file @
fccfbb7d
...
@@ -103,6 +103,7 @@ INSTALLED_APPS = (
...
@@ -103,6 +103,7 @@ INSTALLED_APPS = (
'django.contrib.humanize'
,
'django.contrib.humanize'
,
'static_template_view'
,
'static_template_view'
,
'textbook'
,
'textbook'
,
'staticbook'
,
# Uncomment the next line to enable the admin:
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# Uncomment the next line to enable admin documentation:
...
...
urls.py
View file @
fccfbb7d
...
@@ -19,6 +19,7 @@ urlpatterns = patterns('',
...
@@ -19,6 +19,7 @@ urlpatterns = patterns('',
# url(r'^accounts/', include('registration.urls')),
# url(r'^accounts/', include('registration.urls')),
url
(
r'^t/(?P<template>[^/]*)$'
,
'static_template_view.views.index'
),
url
(
r'^t/(?P<template>[^/]*)$'
,
'static_template_view.views.index'
),
url
(
r'^textbook/(?P<filename>[^/]*)$'
,
'textbook.views.index'
),
url
(
r'^textbook/(?P<filename>[^/]*)$'
,
'textbook.views.index'
),
url
(
r'^book/(?P<page>[^/]*)$'
,
'staticbook.views.index'
),
url
(
r'^logout$'
,
'auth.views.logout_user'
),
url
(
r'^logout$'
,
'auth.views.logout_user'
),
url
(
r'^login$'
,
'auth.views.login_user'
),
url
(
r'^login$'
,
'auth.views.login_user'
),
url
(
r'^login/(?P<error>[^/]*)$'
,
'auth.views.login_user'
),
url
(
r'^login/(?P<error>[^/]*)$'
,
'auth.views.login_user'
),
...
...
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