diff --git a/djangoapps/courseware/capa/capa_problem.py b/djangoapps/courseware/capa/capa_problem.py index 0f9b5dacab..346a4842b3 100644 --- a/djangoapps/courseware/capa/capa_problem.py +++ b/djangoapps/courseware/capa/capa_problem.py @@ -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: diff --git a/djangoapps/courseware/capa/inputtypes.py b/djangoapps/courseware/capa/inputtypes.py index ae8809c066..39aeb1e81a 100644 --- a/djangoapps/courseware/capa/inputtypes.py +++ b/djangoapps/courseware/capa/inputtypes.py @@ -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']