Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
cd67ec8f
Commit
cd67ec8f
authored
12 years ago
by
Piotr Mitros
Browse files
Options
Downloads
Patches
Plain Diff
Modular refactor: Input types look more like x_module
parent
b8b9928a
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
djangoapps/courseware/capa/capa_problem.py
+11
-4
11 additions, 4 deletions
djangoapps/courseware/capa/capa_problem.py
djangoapps/courseware/capa/inputtypes.py
+65
-0
65 additions, 0 deletions
djangoapps/courseware/capa/inputtypes.py
with
76 additions
and
4 deletions
djangoapps/courseware/capa/capa_problem.py
+
11
−
4
View file @
cd67ec8f
...
...
@@ -25,6 +25,7 @@ from mako.template import Template
from
util
import
contextualize_text
import
inputtypes
from
responsetypes
import
NumericalResponse
,
FormulaResponse
,
CustomResponse
,
SchematicResponse
,
MultipleChoiceResponse
,
StudentInputError
,
TrueFalseResponse
,
ExternalResponse
,
ImageResponse
,
OptionResponse
import
calc
...
...
@@ -239,7 +240,7 @@ class LoncapaProblem(object):
# used to be
# if problemtree.tag in html_special_response:
if
hasattr
(
inputtypes
,
problemtree
.
tag
):
if
problemtree
.
tag
in
inputtypes
.
SimpleInput
.
get_xml_
tag
s
(
):
# status is currently the answer for the problem ID for the input element,
# but it will turn into a dict containing both the answer and any associated message
# for the problem ID for the input element.
...
...
@@ -266,9 +267,15 @@ class LoncapaProblem(object):
# print "[courseware.capa.capa_problem.extract_html] msg = ",msg
# do the rendering
#render_function = html_special_response[problemtree.tag]
render_function
=
getattr
(
inputtypes
,
problemtree
.
tag
)
return
render_function
(
problemtree
,
value
,
status
,
msg
)
# render the special response (textline, schematic,...)
render_object
=
inputtypes
.
SimpleInput
(
system
=
self
.
system
,
xml
=
problemtree
,
state
=
{
'
value
'
:
value
,
'
status
'
:
status
,
'
id
'
:
problemtree
.
get
(
'
id
'
),
'
feedback
'
:{
'
message
'
:
msg
}
},
use
=
'
capa_input
'
)
return
render_object
.
get_html
()
#function(problemtree, value, status, msg) # render the special response (textline, schematic,...)
tree
=
Element
(
problemtree
.
tag
)
for
item
in
problemtree
:
...
...
This diff is collapsed.
Click to expand it.
djangoapps/courseware/capa/inputtypes.py
+
65
−
0
View file @
cd67ec8f
...
...
@@ -32,8 +32,15 @@ from lxml import etree
from
mitxmako.shortcuts
import
render_to_string
def
simpleinput
(
fn
):
def
wrapped
():
print
"
XXXXXXXXXXXXX
"
,
fn
return
fn
return
wrapped
#-----------------------------------------------------------------------------
@simpleinput
def
optioninput
(
element
,
value
,
status
,
msg
=
''
):
'''
Select option input type.
...
...
@@ -254,3 +261,61 @@ def imageinput(element, value, status, msg=''):
html
=
render_to_string
(
"
imageinput.html
"
,
context
)
return
etree
.
XML
(
html
)
class
SimpleInput
():
# XModule
'''
Type for simple inputs
State is a dictionary with optional keys:
* Value
* ID
* Status (answered, unanswered, unsubmitted)
* Feedback (dictionary containing keys for hints, errors, or other
feedback from previous attempt)
'''
# We should populate this with a decorator on the specific types
simple_types
=
{
'
choicegroup
'
:
choicegroup
,
'
imageinput
'
:
imageinput
,
'
js_textline
'
:
js_textline
,
'
math
'
:
math
,
'
optioninput
'
:
optioninput
,
'
schematic
'
:
schematic
,
'
solution
'
:
solution
,
'
textbox
'
:
textbox
,
'
textline
'
:
textline
}
@classmethod
def
get_xml_tags
(
c
):
return
c
.
simple_types
.
keys
()
@classmethod
def
get_uses
(
c
):
return
[
'
capa_input
'
]
def
get_html
(
self
):
return
self
.
simple_types
[
self
.
tag
](
self
.
xml
,
self
.
value
,
self
.
status
,
self
.
msg
)
def
__init__
(
self
,
system
,
xml
,
item_id
=
None
,
track_url
=
None
,
state
=
None
,
use
=
'
capa_input
'
):
self
.
xml
=
xml
self
.
tag
=
xml
.
tag
if
not
state
:
state
=
{}
if
item_id
:
self
.
id
=
item_id
if
xml
.
get
(
'
id
'
):
self
.
id
=
xml
.
get
(
'
id
'
)
if
'
id
'
in
state
:
self
.
id
=
state
[
'
id
'
]
self
.
system
=
system
self
.
value
=
''
if
'
value
'
in
state
:
self
.
value
=
state
[
'
value
'
]
self
.
msg
=
''
if
'
feedback
'
in
state
and
'
message
'
in
state
[
'
feedback
'
]:
self
.
msg
=
state
[
'
feedback
'
][
'
message
'
]
self
.
status
=
'
unanswered
'
if
'
status
'
in
state
:
self
.
status
=
state
[
'
status
'
]
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