apluslms/mooc-grader

Hints are not displayed under the checkbox option that they are attached to

markkuriekkinen opened this issue · 3 comments

Some changes during the spring 2021 have broken the hints feature in questionnaires. The hints in checkbox questions are not rendered under the checkbox option, but always under all options. In A+ v1.8 (January 2021), we just got a new improvement and the hints were shown under each checkbox so that it is easier to see which checkbox triggered the hint.

I am also uncertain if the hints are sometimes missing and not rendered at all when they should be visible.

Screenshot from A+ v1.8 (January 2021) in the aplus-manual course. Notice that the checkbox hints are rendered right under each checkbox.
image

image

Seems like this was originally caused by commit ee4f574, when mooc-grader was upgraded to Django 2.2.19. Before the commit, the checkbox hints worked correctly. After the commit, only the hints related to unselected checkboxes remained working.

Before:
image

After:
image

I mentioned this issue here: #104 (comment), and went on to "fix" the issue, but unfortunately I didn't know what the hints were supposed to look like, so now they all end up at the bottom.

I'll find a way to fix this.

Nice catch. I didn't see the problem in hints when I upgraded Django. What could go wrong with the Django upgrade:

  • there may be minor changes in the Form API. The questionnaire grading uses a Django form: https://github.com/apluslms/mooc-grader/blob/master/access/types/forms.py
  • the code for hints are messy and it even mixes types. The hints variable is sometimes a list and sometimes a dictionary. As far as I remember, it was necessary to use dictionaries for the improved checkbox hints so that they can be rendered under the checkbox. But most of the code uses a hints list:
    def append_hint(self, hints, configuration):
    # The old definition of hint per option.
    hint = str(configuration.get('hint', ''))
    if hint and not hint in hints:
    hints.append(hint)
    def append_hint_checkbox(self, hints, configuration):
    hint = str(configuration.get('hint', ''))
    if hint and not hint in hints:
    hints['hint'] = hint

    hints = OrderedDict()
  • The Django template syntax has also changed. I remember that Django 1.9 did not support some combination of logical operators (and, or, not) in the same if condition. Django 2.2 is more flexible and supports more complex logical expressions.

The problem lies in graded_form.html. Before the upgrade, the line {% for choice in field %} yielded CheckboxChoiceInput instances, but after the upgrade it yields BoundWidget instances. The template rendering relied on the value and choice_value attributes of the CheckboxChoiceInput but these aren't available in the BoundWidgetclass. I'll try to update the template so that it works with the new class.