#13 Declined
Repository
sedah sedah
Branch
default
Repository
slav0nic slav0nic
Branch
default

Fixed handling of single choice poll results.

Author
  1. sedah avatarsedah
Reviewers
Description
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 :)))

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.