From 35a08b8541c856a51b2ab718e0a2fe060debfa2a Mon Sep 17 00:00:00 2001 From: Basil Dubyk Date: Wed, 14 Nov 2018 20:43:34 +0200 Subject: [PATCH] Fixed #17210 -- Made NullBooleanSelect use unknown/true/false as query data. --- django/forms/widgets.py | 22 ++++-- docs/releases/2.2.txt | 5 ++ tests/forms_tests/tests/test_forms.py | 72 ++++++++++------- .../widget_tests/test_nullbooleanselect.py | 77 +++++++++++++++---- 4 files changed, 126 insertions(+), 50 deletions(-) diff --git a/django/forms/widgets.py b/django/forms/widgets.py index e4f8957189..eed1fa5c3b 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -696,27 +696,35 @@ class NullBooleanSelect(Select): """ def __init__(self, attrs=None): choices = ( - ('1', _('Unknown')), - ('2', _('Yes')), - ('3', _('No')), + ('unknown', _('Unknown')), + ('true', _('Yes')), + ('false', _('No')), ) super().__init__(attrs, choices) def format_value(self, value): try: - return {True: '2', False: '3', '2': '2', '3': '3'}[value] + return { + True: 'true', False: 'false', + 'true': 'true', 'false': 'false', + # For backwards compatibility with Django < 2.2. + '2': 'true', '3': 'false', + }[value] except KeyError: - return '1' + return 'unknown' def value_from_datadict(self, data, files, name): value = data.get(name) return { - '2': True, True: True, 'True': True, - '3': False, 'False': False, False: False, + 'true': True, + 'false': False, + # For backwards compatibility with Django < 2.2. + '2': True, + '3': False, }.get(value) diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index debc60c5f6..a8bd9ab488 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -380,6 +380,11 @@ Miscellaneous * Support for ``cx_Oracle`` < 6.0 is removed. +* In an attempt to provide more semantic query data, ``NullBooleanSelect`` now + renders ``