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
cd67ec8f
Commit
cd67ec8f
authored
May 20, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modular refactor: Input types look more like x_module
parent
b8b9928a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
4 deletions
+76
-4
djangoapps/courseware/capa/capa_problem.py
+11
-4
djangoapps/courseware/capa/inputtypes.py
+65
-0
No files found.
djangoapps/courseware/capa/capa_problem.py
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_tags
(
):
# 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
:
...
...
djangoapps/courseware/capa/inputtypes.py
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'
]
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