Skip to content

Commit

Permalink
frontend/mcq : Allowing task creator to (not) shuffle choices.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drumor committed Jun 16, 2021
1 parent 0c9a010 commit a870ab4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion inginious/common/tasks_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def __init__(self, problemid, content, translations, taskfs):
super(MultipleChoiceProblem, self).__init__(problemid, content, translations, taskfs)
self._header = content['header'] if "header" in content else ""
self._multiple = content.get("multiple", False)
self._shuffle = content.get("shuffle", False)
if "choices" not in content or not isinstance(content['choices'], (list, tuple)):
raise Exception("Multiple choice problem " + problemid + " does not have choices or choices are not an array")
good_choices = []
Expand Down Expand Up @@ -330,7 +331,7 @@ def check_answer(self, task_input, language):
def parse_problem(self, problem_content):
problem_content = Problem.parse_problem(problem_content)
# store boolean fields as booleans
for field in ["optional", "multiple", "centralize"]:
for field in ["optional", "multiple", "centralize","shuffle"]:
if field in problem_content:
problem_content[field] = True

Expand Down
2 changes: 2 additions & 0 deletions inginious/frontend/static/js/studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ function studio_init_template_multiple_choice(well, pid, problem)
$('#multiple-' + pid, well).attr('checked', true);
if("centralize" in problem && problem["centralize"])
$('#centralize-' + pid, well).attr('checked', true);
if("shuffle" in problem && problem["shuffle"])
$('#shuffle-' + pid, well).attr('checked', true);

var success_message = "";
var error_message = "";
Expand Down
8 changes: 4 additions & 4 deletions inginious/frontend/task_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ def show_input(self, template_helper, language, seed):
if entry['valid'] and limit > 0:
choices.append(entry)
limit = limit - 1

rand.shuffle(choices)

if self._shuffle:
rand.shuffle(choices)
else:
choices = sorted(choices, key=lambda k: k['index'])
header = ParsableText(self.gettext(language, self._header), "rst",
translation=self.get_translation_obj(language))

return template_helper.render("tasks/multiple_choice.html", pid=self.get_id(), header=header,
checkbox=self._multiple, choices=choices,
func=lambda text: ParsableText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
</label></div>
</div>
</div>
<div class="form-group row">
<label for="shuffle-PID" class="col-sm-2 control-label">{{ _("Shuffle answers") }}</label>
<div class="col-sm-10">
<div class="checkbox"><label>
<input type="checkbox" id="shuffle-PID" name="problem[PID][shuffle]"/>&nbsp;
</label></div>
</div>
</div>
<div class="form-group row">
<label for="centralize-PID" class="col-sm-2 control-label">{{ _("Count error only at top of the page?") }}</label>
<div class="col-sm-10">
Expand Down

0 comments on commit a870ab4

Please sign in to comment.