diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index ca78f635e3..d868e66ec5 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -56,7 +56,8 @@ entry_types = ['textline', 'checkboxgroup', 'filesubmission', 'javascriptinput', - 'chemicalequationinput'] + 'crystallography', + 'chemicalequationinput',] # extra things displayed after "show answers" is pressed solution_types = ['solution'] diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 297350be03..0e993c1366 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -707,6 +707,50 @@ def imageinput(element, value, status, render_template, msg=''): _reg(imageinput) +#----------------------------------------------------------------------------- +def crystallography(element, value, status, render_template, msg=''): + eid = element.get('id') + if eid is None: + msg = 'cryst has no id: it probably appears outside of a known response type' + msg += "\nSee problem XML source line %s" % getattr(element, 'sourceline', '') + raise Exception(msg) + height = element.get('height') + width = element.get('width') + display_file = element.get('display_file') + + count = int(eid.split('_')[-2]) - 1 # HACK + size = element.get('size') + # if specified, then textline is hidden and id is stored in div of name given by hidden + hidden = element.get('hidden', '') + # Escape answers with quotes, so they don't crash the system! + escapedict = {'"': '"'} + value = saxutils.escape(value, escapedict) + + context = {'id': eid, + 'value': value, + 'state': status, + 'count': count, + 'size': size, + 'msg': msg, + 'hidden': hidden, + 'inline': element.get('inline', ''), + 'width': width, + 'height': height, + 'display_file': display_file, + } + + html = render_template("crystallography.html", context) + try: + xhtml = etree.XML(html) + except Exception as err: + # TODO: needs to be self.system.DEBUG - but can't access system + if True: + log.debug('[inputtypes.textline] failed to parse XML for:\n%s' % html) + raise + return xhtml + +_reg(crystallography) + #-------------------------------------------------------------------------------- diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index eb739c9b72..269b4a5e79 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -867,7 +867,7 @@ def sympy_check2(): """}] response_tag = 'customresponse' - allowed_inputfields = ['textline', 'textbox', 'chemicalequationinput'] + allowed_inputfields = ['textline', 'textbox', 'crystallography', 'chemicalequationinput'] def setup_response(self): xml = self.xml diff --git a/common/lib/capa/capa/templates/crystallography.html b/common/lib/capa/capa/templates/crystallography.html new file mode 100644 index 0000000000..1fc638b356 --- /dev/null +++ b/common/lib/capa/capa/templates/crystallography.html @@ -0,0 +1,51 @@ +<% doinline = "inline" if inline else "" %> + +
+
+
+
+ + + % if state == 'unsubmitted': +
+ % elif state == 'correct': +
+ % elif state == 'incorrect': +
+ % elif state == 'incomplete': +
+ % endif + % if hidden: +
+ % endif + + + +

+ % if state == 'unsubmitted': + unanswered + % elif state == 'correct': + correct + % elif state == 'incorrect': + incorrect + % elif state == 'incomplete': + incomplete + % endif +

+ +

+ + % if msg: + ${msg|n} + % endif +% if state in ['unsubmitted', 'correct', 'incorrect', 'incomplete'] or hidden: +
+% endif +