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
e31356b1
Commit
e31356b1
authored
Dec 16, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better/more AJAXy problem rendering
parent
0fec3df8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
14 deletions
+32
-14
courseware/capa_module.py
+29
-12
courseware/static/schematic.js
+0
-0
courseware/views.py
+3
-2
No files found.
courseware/capa_module.py
View file @
e31356b1
...
...
@@ -30,7 +30,19 @@ class LoncapaModule(XModule):
def
max_score
(
self
):
return
len
(
self
.
lcp
.
questions
)
def
get_html
(
self
,
encapsulate
=
True
):
def
get_html
(
self
):
return
render_to_string
(
'problem_ajax.html'
,
{
'id'
:
self
.
filename
,
'ajax_url'
:
self
.
ajax_url
,
})
def
get_init_js
(
self
):
return
render_to_string
(
'problem.js'
,
{
'id'
:
self
.
filename
,
'ajax_url'
:
self
.
ajax_url
,
})
def
get_problem_html
(
self
,
encapsulate
=
True
):
html
=
self
.
lcp
.
get_html
()
content
=
{
'name'
:
self
.
name
,
'html'
:
html
}
...
...
@@ -47,11 +59,9 @@ class LoncapaModule(XModule):
})
if
encapsulate
:
html
=
'<div id="main_{id}">'
.
format
(
id
=
self
.
item_id
)
+
html
+
"</div>"
return
html
def
get_init_js
(
self
):
return
""
def
__init__
(
self
,
xml
,
item_id
,
ajax_url
=
None
,
track_url
=
None
,
state
=
None
):
XModule
.
__init__
(
self
,
xml
,
item_id
,
ajax_url
,
track_url
,
state
)
dom
=
parseString
(
xml
)
...
...
@@ -63,17 +73,25 @@ class LoncapaModule(XModule):
def
handle_ajax
(
self
,
dispatch
,
get
):
if
dispatch
==
'problem_check'
:
html
=
self
.
check_problem
(
get
)
response
=
self
.
check_problem
(
get
)
elif
dispatch
==
'problem_reset'
:
html
=
self
.
reset_problem
(
get
)
response
=
self
.
reset_problem
(
get
)
elif
dispatch
==
'problem_get'
:
response
=
self
.
get_problem
(
get
)
else
:
return
"Error"
return
html
return
response
# Temporary -- move to capa_problem
# Figure out if we should move these to capa_problem?
def
get_problem
(
self
,
get
):
''' Same as get_problem_html -- if we want to reconfirm we have the right
thing e.g. after several AJAX calls. '''
return
self
.
get_problem_html
(
encapsulate
=
False
)
def
check_problem
(
self
,
get
):
''' Checks whether answers to a problem are correct, and returns
a map of correct/incorrect answers '''
self
.
lcp
.
done
=
True
answer
=
dict
()
# input_resistor_1 ==> resistor_1
...
...
@@ -85,6 +103,8 @@ class LoncapaModule(XModule):
return
js
def
reset_problem
(
self
,
get
):
''' Changes problem state to unfinished -- removes student answers,
and causes problem to rerender itself. '''
self
.
lcp
.
done
=
False
self
.
lcp
.
answers
=
dict
()
self
.
lcp
.
context
=
dict
()
...
...
@@ -92,9 +112,6 @@ class LoncapaModule(XModule):
self
.
lcp
.
answers
=
dict
()
# Student answers
self
.
lcp
.
correct_map
=
dict
()
self
.
lcp
.
seed
=
None
# Minor cleanup would be nice
# We recreate the capa_problem on a reset
filename
=
settings
.
DATA_DIR
+
self
.
filename
+
".xml"
self
.
lcp
=
LoncapaProblem
(
filename
,
self
.
item_id
,
self
.
lcp
.
get_state
())
# self.lcp.__init__(filename, self.item_id, self.lcp.get_state())
return
json
.
dumps
(
self
.
get_html
(
encapsulate
=
False
))
return
json
.
dumps
(
self
.
get_problem_html
(
encapsulate
=
False
))
courseware/static/schematic.js
0 → 100644
View file @
e31356b1
This diff is collapsed.
Click to expand it.
courseware/views.py
View file @
e31356b1
...
...
@@ -188,7 +188,7 @@ def render_x_module(request, xml_module):
return
content
def
modx_dispatch
(
request
,
module
=
None
,
dispatch
=
None
,
id
=
None
):
''' Generic module for extensions.
This handles AJAX.
'''
''' Generic module for extensions. '''
s
=
StudentModule
.
objects
.
filter
(
module_type
=
module
,
student
=
request
.
user
,
module_id
=
id
)
if
len
(
s
)
==
0
:
raise
Http404
...
...
@@ -229,7 +229,8 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/'
)
# Fix URLs
# Fixes URLs -- we don't get funny encoding characters from spaces
# so they remain readable
course
=
course
.
replace
(
"_"
,
" "
)
chapter
=
chapter
.
replace
(
"_"
,
" "
)
section
=
section
.
replace
(
"_"
,
" "
)
...
...
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