Opened 17 years ago

Closed 16 years ago

#6937 closed (fixed)

newforms BooleanField should be more tolerant of different inputs

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

Description

Here's how BooleanField works at the moment:

http://code.djangoproject.com/browser/django/trunk/django/newforms/fields.py#L534

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 Andrew Gibson 16 years ago.
one line change plus tests

Download all attachments as: .zip

Change History (7)

comment:1 by Chris Beaven, 17 years ago

Triage Stage: UnreviewedDesign 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 by Chris Beaven, 17 years ago

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

comment:3 by Andrew Gibson, 16 years ago

Owner: changed from nobody to Andrew Gibson
Status: newassigned

by Andrew Gibson, 16 years ago

Attachment: patch.diff added

one line change plus tests

comment:4 by Andrew Gibson, 16 years ago

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 by Chris Beaven, 16 years ago

Patch needs improvement: set

checking type against str isn't very good

comment:6 by Chris Beaven, 16 years ago

Resolution: fixed
Status: assignedclosed

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