Python django.forms.NullBooleanField() Examples
The following are 30
code examples of django.forms.NullBooleanField().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.forms
, or try the search function
.
Example #1
Source File: test_nullbooleanfield.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_nullbooleanfield_changed(self): f = NullBooleanField() self.assertTrue(f.has_changed(False, None)) self.assertTrue(f.has_changed(None, False)) self.assertFalse(f.has_changed(None, None)) self.assertFalse(f.has_changed(False, False)) self.assertTrue(f.has_changed(True, False)) self.assertTrue(f.has_changed(True, None)) self.assertTrue(f.has_changed(True, False)) # HiddenInput widget sends string values for boolean but doesn't clean them in value_from_datadict self.assertFalse(f.has_changed(False, 'False')) self.assertFalse(f.has_changed(True, 'True')) self.assertFalse(f.has_changed(None, '')) self.assertTrue(f.has_changed(False, 'True')) self.assertTrue(f.has_changed(True, 'False')) self.assertTrue(f.has_changed(None, 'False'))
Example #2
Source File: test_nullbooleanfield.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_nullbooleanfield_changed(self): f = NullBooleanField() self.assertTrue(f.has_changed(False, None)) self.assertTrue(f.has_changed(None, False)) self.assertFalse(f.has_changed(None, None)) self.assertFalse(f.has_changed(False, False)) self.assertTrue(f.has_changed(True, False)) self.assertTrue(f.has_changed(True, None)) self.assertTrue(f.has_changed(True, False)) # HiddenInput widget sends string values for boolean but doesn't clean them in value_from_datadict self.assertFalse(f.has_changed(False, 'False')) self.assertFalse(f.has_changed(True, 'True')) self.assertFalse(f.has_changed(None, '')) self.assertTrue(f.has_changed(False, 'True')) self.assertTrue(f.has_changed(True, 'False')) self.assertTrue(f.has_changed(None, 'False'))
Example #3
Source File: __init__.py From openhgsenti with Apache License 2.0 | 5 votes |
def formfield(self, **kwargs): defaults = { 'form_class': forms.NullBooleanField, 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text} defaults.update(kwargs) return super(NullBooleanField, self).formfield(**defaults)
Example #4
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def __init__(self, *args, **kwargs): kwargs['null'] = True kwargs['blank'] = True super(NullBooleanField, self).__init__(*args, **kwargs)
Example #5
Source File: __init__.py From python2017 with MIT License | 5 votes |
def _check_null(self, **kwargs): if getattr(self, 'null', False): return [ checks.Error( 'BooleanFields do not accept null values.', hint='Use a NullBooleanField instead.', obj=self, id='fields.E110', ) ] else: return []
Example #6
Source File: __init__.py From python2017 with MIT License | 5 votes |
def __init__(self, *args, **kwargs): kwargs['null'] = True kwargs['blank'] = True super(NullBooleanField, self).__init__(*args, **kwargs)
Example #7
Source File: __init__.py From python2017 with MIT License | 5 votes |
def deconstruct(self): name, path, args, kwargs = super(NullBooleanField, self).deconstruct() del kwargs['null'] del kwargs['blank'] return name, path, args, kwargs
Example #8
Source File: __init__.py From python2017 with MIT License | 5 votes |
def get_internal_type(self): return "NullBooleanField"
Example #9
Source File: __init__.py From python2017 with MIT License | 5 votes |
def get_prep_value(self, value): value = super(NullBooleanField, self).get_prep_value(value) if value is None: return None return self.to_python(value)
Example #10
Source File: test_converter.py From graphene-django with MIT License | 5 votes |
def test_should_nullboolean_convert_boolean(): field = assert_conversion(forms.NullBooleanField, Boolean) assert not isinstance(field.type, NonNull)
Example #11
Source File: test_nullbooleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_clean(self): f = NullBooleanField() self.assertIsNone(f.clean('')) self.assertTrue(f.clean(True)) self.assertFalse(f.clean(False)) self.assertIsNone(f.clean(None)) self.assertFalse(f.clean('0')) self.assertTrue(f.clean('1')) self.assertIsNone(f.clean('2')) self.assertIsNone(f.clean('3')) self.assertIsNone(f.clean('hello')) self.assertTrue(f.clean('true')) self.assertFalse(f.clean('false'))
Example #12
Source File: test_nullbooleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_2(self): # The internal value is preserved if using HiddenInput (#7753). class HiddenNullBooleanForm(Form): hidden_nullbool1 = NullBooleanField(widget=HiddenInput, initial=True) hidden_nullbool2 = NullBooleanField(widget=HiddenInput, initial=False) f = HiddenNullBooleanForm() self.assertHTMLEqual( '<input type="hidden" name="hidden_nullbool1" value="True" id="id_hidden_nullbool1">' '<input type="hidden" name="hidden_nullbool2" value="False" id="id_hidden_nullbool2">', str(f) )
Example #13
Source File: test_nullbooleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_3(self): class HiddenNullBooleanForm(Form): hidden_nullbool1 = NullBooleanField(widget=HiddenInput, initial=True) hidden_nullbool2 = NullBooleanField(widget=HiddenInput, initial=False) f = HiddenNullBooleanForm({'hidden_nullbool1': 'True', 'hidden_nullbool2': 'False'}) self.assertIsNone(f.full_clean()) self.assertTrue(f.cleaned_data['hidden_nullbool1']) self.assertFalse(f.cleaned_data['hidden_nullbool2'])
Example #14
Source File: test_nullbooleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_4(self): # Make sure we're compatible with MySQL, which uses 0 and 1 for its # boolean values (#9609). NULLBOOL_CHOICES = (('1', 'Yes'), ('0', 'No'), ('', 'Unknown')) class MySQLNullBooleanForm(Form): nullbool0 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES)) nullbool1 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES)) nullbool2 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES)) f = MySQLNullBooleanForm({'nullbool0': '1', 'nullbool1': '0', 'nullbool2': ''}) self.assertIsNone(f.full_clean()) self.assertTrue(f.cleaned_data['nullbool0']) self.assertFalse(f.cleaned_data['nullbool1']) self.assertIsNone(f.cleaned_data['nullbool2'])
Example #15
Source File: test_booleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_old_to_python(self): self._test_to_python(models.NullBooleanField())
Example #16
Source File: test_booleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_formfield(self): f = models.BooleanField(null=True) self.assertIsInstance(f.formfield(), forms.NullBooleanField) f = models.NullBooleanField() self.assertIsInstance(f.formfield(), forms.NullBooleanField)
Example #17
Source File: test_booleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_blank(self): """ NullBooleanField shouldn't throw a validation error when given a value of None. """ nullboolean = NullBooleanModel(nbfield=None, nbfield_old=None) nullboolean.full_clean()
Example #18
Source File: test_nullbooleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_clean(self): f = NullBooleanField() self.assertIsNone(f.clean('')) self.assertTrue(f.clean(True)) self.assertFalse(f.clean(False)) self.assertIsNone(f.clean(None)) self.assertFalse(f.clean('0')) self.assertTrue(f.clean('1')) self.assertIsNone(f.clean('2')) self.assertIsNone(f.clean('3')) self.assertIsNone(f.clean('hello')) self.assertTrue(f.clean('true')) self.assertFalse(f.clean('false'))
Example #19
Source File: test_nullbooleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_2(self): # The internal value is preserved if using HiddenInput (#7753). class HiddenNullBooleanForm(Form): hidden_nullbool1 = NullBooleanField(widget=HiddenInput, initial=True) hidden_nullbool2 = NullBooleanField(widget=HiddenInput, initial=False) f = HiddenNullBooleanForm() self.assertHTMLEqual( '<input type="hidden" name="hidden_nullbool1" value="True" id="id_hidden_nullbool1">' '<input type="hidden" name="hidden_nullbool2" value="False" id="id_hidden_nullbool2">', str(f) )
Example #20
Source File: test_nullbooleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_4(self): # Make sure we're compatible with MySQL, which uses 0 and 1 for its # boolean values (#9609). NULLBOOL_CHOICES = (('1', 'Yes'), ('0', 'No'), ('', 'Unknown')) class MySQLNullBooleanForm(Form): nullbool0 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES)) nullbool1 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES)) nullbool2 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES)) f = MySQLNullBooleanForm({'nullbool0': '1', 'nullbool1': '0', 'nullbool2': ''}) self.assertIsNone(f.full_clean()) self.assertTrue(f.cleaned_data['nullbool0']) self.assertFalse(f.cleaned_data['nullbool1']) self.assertIsNone(f.cleaned_data['nullbool2'])
Example #21
Source File: test_booleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_old_get_prep_value(self): self._test_get_prep_value(models.NullBooleanField())
Example #22
Source File: test_booleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_old_to_python(self): self._test_to_python(models.NullBooleanField())
Example #23
Source File: test_booleanfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_nullbooleanfield_formfield(self): f = models.BooleanField(null=True) self.assertIsInstance(f.formfield(), forms.NullBooleanField) f = models.NullBooleanField() self.assertIsInstance(f.formfield(), forms.NullBooleanField)
Example #24
Source File: __init__.py From openhgsenti with Apache License 2.0 | 5 votes |
def get_internal_type(self): return "NullBooleanField"
Example #25
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def _check_null(self, **kwargs): if getattr(self, 'null', False): return [ checks.Error( 'BooleanFields do not accept null values.', hint='Use a NullBooleanField instead.', obj=self, id='fields.E110', ) ] else: return []
Example #26
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def deconstruct(self): name, path, args, kwargs = super(NullBooleanField, self).deconstruct() del kwargs['null'] del kwargs['blank'] return name, path, args, kwargs
Example #27
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def get_internal_type(self): return "NullBooleanField"
Example #28
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def get_prep_lookup(self, lookup_type, value): # Special-case handling for filters coming from a Web request (e.g. the # admin interface). Only works for scalar values (not lists). If you're # passing in a list, you might as well make things the right type when # constructing the list. if value in ('1', '0'): value = bool(int(value)) return super(NullBooleanField, self).get_prep_lookup(lookup_type, value)
Example #29
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def formfield(self, **kwargs): defaults = { 'form_class': forms.NullBooleanField, 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text} defaults.update(kwargs) return super(NullBooleanField, self).formfield(**defaults)
Example #30
Source File: __init__.py From bioforum with MIT License | 5 votes |
def _check_null(self, **kwargs): if getattr(self, 'null', False): return [ checks.Error( 'BooleanFields do not accept null values.', hint='Use a NullBooleanField instead.', obj=self, id='fields.E110', ) ] else: return []