Fixed handling of single choice poll results.

#13 Declined
  1. sedah
No description

Comments (9)

  1. Jens Diemer

    """self.cleaned_data["choice"]""" didn't return a list, if there is only one choice?

    In this case, a better solution is maybe to change this in the form and return always a list.

  2. sedah author

    The form replaces multiple choice field with single choice, if only 1 choice is allowed. Hence it returns sometimes list, and sometimes a scalar.

  3. Andrei Kavaleu

    The reason of this bug is: for multiple choice pools the form uses MultipleChoiceField and CheckboxSelectMultiple widget, but for single choice pools it uses ChoiceField and RadioSelect. RadioSelect+ChoiceField returns only the choice itself, not a list (string id in this case). When we ask len("13"), for example, it returns 2, so validation fails.

    The best solution I've found so far is a variation of sedah's solution, but with a reasonable check (not the "instance of" magic):

    if self.poll.choice_count == 1:
        ids = [ids]
  4. Andrei Kavaleu

    Sedah, I agree there is nothing magical in instance check itself. However if you read the code and see "if not isinstance(ids, list)" this looks really magical (why do we need to check for instance of list, not for something else. And why ids could be something but list).

    Anyway, thanks for your solution, it was my starting point for the issue. I just upgraded your solution with a "business-logic" related check.

  5. sedah author

    if you read the code and see "if not isinstance(ids, list)" this looks really magical

    This is highly subjective.

    Anyway, thanks

    You're very welcome.

  6. Andrei Kavaleu

    This is highly subjective.

    :) Not sure, to be honest. :) This is my opinion, so it could be really subjective ;-)

    Anyway, lets wait for the owner of this repo. He can probably reject both solutions :)))