Accept either a list of possible values, or a string as a value for

comparison of correctness in multiple choice.

Multiple choice code is scattered and sometimes sends a list of
choices for the value, and sometimes a single string. We used to use
"in" which scarily handled both cases (list or substring search),
but that caused a bug when you had two choices like choice_1 and
choice10. Moving to == caused us to break when lists were sent to
us. So this ugly code is extra paranoid and checks both possibilities.

This really needs a better cleanup.
This commit is contained in:
David Ormsbee
2013-03-30 11:09:44 -04:00
parent f6e9b2edd7
commit dfd3a699b9

View File

@@ -17,7 +17,7 @@
% for choice_id, choice_description in choices:
<label for="input_${id}_${choice_id}"
% if input_type == 'radio' and choice_id == value:
% if input_type == 'radio' and ( (isinstance(value, basestring) and (choice_id == value)) or (not isinstance(value, basestring) and choice_id in value) ):
<%
if status == 'correct':
correctness = 'correct'
@@ -30,9 +30,9 @@
class="choicegroup_${correctness}"
% endif
% endif
>
>
<input type="${input_type}" name="input_${id}${name_array_suffix}" id="input_${id}_${choice_id}" value="${choice_id}"
% if input_type == 'radio' and choice_id == value:
% if input_type == 'radio' and ( (isinstance(value, basestring) and (choice_id == value)) or (not isinstance(value, basestring) and choice_id in value) ):
checked="true"
% elif input_type != 'radio' and choice_id in value:
checked="true"