Opened 8 years ago

Closed 7 years ago

#6937 closed (fixed)

newforms BooleanField should be more tolerant of different inputs

Reported by: Simon Willison Owned by: mysliceof314
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:


Here's how BooleanField works at the moment:

if value == 'False':
    return False
return bool(value)

It would be really nice if it had a slightly more human-friendly idea of what constituted true and false values. For example, '1' v.s. '0', 'true' v.s. 'false', 'yes' v.s. 'no' etc. At the moment it assumes it will only be called from a check box widget, but there are times when this code will be used for input that didn't come from an HTML form.

Attachments (1)

patch.diff (1.2 KB) - added by mysliceof314 8 years ago.
one line change plus tests

Download all attachments as: .zip

Change History (7)

comment:1 Changed 8 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

Easy to implement, just need a call from core whether we want to do this...

if value.lower() in ('0', 'false', 'no'):
    return False
return bool(value)

comment:2 Changed 8 years ago by SmileyChris

(of course, that was a naive prototype, you should check that value is a string too)

comment:3 Changed 8 years ago by mysliceof314

  • Owner changed from nobody to mysliceof314
  • Status changed from new to assigned

Changed 8 years ago by mysliceof314

one line change plus tests

comment:4 Changed 8 years ago by mysliceof314

  • Has patch set

My first attempt at submitting a patch. I know it's not a big deal, was just trying to learn the process. Hope it helps:)

comment:5 Changed 7 years ago by SmileyChris

  • Patch needs improvement set

checking type against str isn't very good

comment:6 Changed 7 years ago by SmileyChris

  • Resolution set to fixed
  • Status changed from assigned to closed

This is actually a dupe ticket - it was fixed somewhere along the way (for '0' at least)

Note: See TracTickets for help on using tickets.
Back to Top