More minor cleanups
This commit is contained in:
committed by
Piotr Mitros
parent
668062a19b
commit
747105e328
@@ -1,11 +1,34 @@
|
||||
#
|
||||
# File: courseware/capa/inputtypes.py
|
||||
#
|
||||
|
||||
'''
|
||||
Module containing the problem elements which render into input objects
|
||||
|
||||
- textline
|
||||
- textbox (change this to textarea?)
|
||||
- schemmatic
|
||||
|
||||
These are matched by *.html files templates/*.html which are mako templates with the actual html.
|
||||
|
||||
'''
|
||||
|
||||
|
||||
from lxml.etree import Element
|
||||
from lxml import etree
|
||||
|
||||
from mitxmako.shortcuts import render_to_string
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#takes the xml tree as 'element', the student's previous answer as 'value', and the graded status as 'state'
|
||||
|
||||
def choicegroup(element, value, state):
|
||||
'''
|
||||
Radio button inputs: multiple choice or true/false
|
||||
|
||||
TODO: allow order of choices to be randomized, following lon-capa spec. Use "location" attribute,
|
||||
ie random, top, bottom.
|
||||
'''
|
||||
eid=element.get('id')
|
||||
if element.get('type') == "MultipleChoice":
|
||||
type="radio"
|
||||
@@ -16,7 +39,7 @@ def choicegroup(element, value, state):
|
||||
choices={}
|
||||
for choice in element:
|
||||
assert choice.tag =="choice", "only <choice> tags should be immediate children of a <choicegroup>"
|
||||
choices[choice.get("name")] = etree.tostring(choice[0])
|
||||
choices[choice.get("name")] = etree.tostring(choice[0]) # TODO: what if choice[0] has math tags in it?
|
||||
context={'id':eid, 'value':value, 'state':state, 'type':type, 'choices':choices}
|
||||
html=render_to_string("choicegroup.html", context)
|
||||
return etree.XML(html)
|
||||
|
||||
Reference in New Issue
Block a user