Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
1ec3209d
Commit
1ec3209d
authored
13 years ago
by
Piotr Mitros
Browse files
Options
Downloads
Patches
Plain Diff
Moved courseware from minidom to lxml2. Appears to work, but big change. may still have bugs.
parent
8539b926
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
courseware/module_render.py
+15
-14
15 additions, 14 deletions
courseware/module_render.py
courseware/views.py
+49
-1
49 additions, 1 deletion
courseware/views.py
with
64 additions
and
15 deletions
courseware/module_render.py
+
15
−
14
View file @
1ec3209d
...
...
@@ -29,6 +29,9 @@ from django.conf import settings
import
content_parser
import
sys
from
lxml
import
etree
import
uuid
modx_modules
=
{
'
problem
'
:
capa_module
.
LoncapaModule
,
...
...
@@ -80,9 +83,8 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
def
vertical_module
(
request
,
module
):
'''
Layout module which lays out content vertically.
'''
contents
=
[(
e
.
getAttribute
(
"
name
"
),
render_module
(
request
,
e
))
\
for
e
in
module
.
childNodes
\
if
e
.
nodeType
==
1
]
contents
=
[(
e
.
get
(
"
name
"
),
render_module
(
request
,
e
))
\
for
e
in
module
]
init_js
=
""
.
join
([
e
[
1
][
'
init_js
'
]
for
e
in
contents
if
'
init_js
'
in
e
[
1
]])
destroy_js
=
""
.
join
([
e
[
1
][
'
destroy_js
'
]
for
e
in
contents
if
'
destroy_js
'
in
e
[
1
]])
...
...
@@ -107,9 +109,8 @@ def seq_module(request, module):
"
destroy_js
"
:
m
[
'
destroy_js
'
],
'
init_js
'
:
m
[
'
init_js
'
],
'
type
'
:
m
[
'
type
'
]}
contents
=
[(
e
.
getAttribute
(
"
name
"
),
j
(
render_module
(
request
,
e
)))
\
for
e
in
module
.
childNodes
\
if
e
.
nodeType
==
1
]
contents
=
[(
e
.
get
(
"
name
"
),
j
(
render_module
(
request
,
e
)))
\
for
e
in
module
]
js
=
""
...
...
@@ -125,12 +126,12 @@ def seq_module(request, module):
# IDs to sequences.
destroy_js
=
""
.
join
([
e
[
1
][
'
destroy_js
'
]
for
e
in
contents
if
'
destroy_js
'
in
e
[
1
]])
if
module
.
nodeName
==
'
sequential
'
:
if
module
.
tag
==
'
sequential
'
:
return
{
'
init_js
'
:
js
+
render_to_string
(
'
seq_module.js
'
,
params
),
"
destroy_js
"
:
destroy_js
,
'
content
'
:
render_to_string
(
'
seq_module.html
'
,
params
),
'
type
'
:
'
sequential
'
}
if
module
.
nodeName
==
'
tab
'
:
if
module
.
tag
==
'
tab
'
:
params
[
'
id
'
]
=
'
tab
'
return
{
'
init_js
'
:
js
+
render_to_string
(
'
tab_module.js
'
,
params
),
"
destroy_js
"
:
destroy_js
,
...
...
@@ -141,9 +142,9 @@ def seq_module(request, module):
def
render_x_module
(
request
,
xml_module
):
'''
Generic module for extensions. This renders to HTML.
'''
# Check if problem has an instance in DB
module_type
=
xml_module
.
nodeName
module_type
=
xml_module
.
tag
module_class
=
modx_modules
[
module_type
]
module_id
=
xml_module
.
get
Attribute
(
module_class
.
id_attribute
)
module_id
=
xml_module
.
get
(
module_class
.
id_attribute
)
or
""
# TODO: remove or ""
# Grab state from database
s
=
StudentModule
.
objects
.
filter
(
student
=
request
.
user
,
...
...
@@ -157,7 +158,7 @@ def render_x_module(request, xml_module):
# Create a new instance
ajax_url
=
'
/modx/
'
+
module_type
+
'
/
'
+
module_id
+
'
/
'
instance
=
module_class
(
xml_module
.
toxml
(
),
instance
=
module_class
(
etree
.
tostring
(
xml_module
),
module_id
,
ajax_url
=
ajax_url
,
state
=
state
,
...
...
@@ -190,9 +191,9 @@ module_types={'video':render_x_module,
def
render_module
(
request
,
module
):
'''
Generic dispatch for internal modules.
'''
if
module
==
None
:
if
module
==
None
:
return
{
"
content
"
:
""
}
if
str
(
module
.
localName
)
in
module_types
:
return
module_types
[
module
.
localName
](
request
,
module
)
if
str
(
module
.
tag
)
in
module_types
:
return
module_types
[
module
.
tag
](
request
,
module
)
print
"
rm404
"
raise
Http404
This diff is collapsed.
Click to expand it.
courseware/views.py
+
49
−
1
View file @
1ec3209d
from
django.http
import
HttpResponse
from
django.template
import
Context
,
loader
from
djangomako.shortcuts
import
render_to_response
,
render_to_string
from
xml.dom.minidom
import
parse
,
parseString
import
json
,
os
,
sys
from
django.core.context_processors
import
csrf
...
...
@@ -33,6 +32,9 @@ from module_render import *
from
lxml
import
etree
etree
.
set_default_parser
(
etree
.
XMLParser
(
dtd_validation
=
False
,
load_dtd
=
False
,
remove_comments
=
True
))
template_imports
=
{
'
urllib
'
:
urllib
}
def
profile
(
request
):
...
...
@@ -114,6 +116,7 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
# 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
(
"
_
"
,
"
"
)
...
...
@@ -147,3 +150,48 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
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_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)
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
:
module
=
None
else
:
module
=
dom_module
[
0
]
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment