django.forms.NullBooleanField - python examples

Here are the examples of the python api django.forms.NullBooleanField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

13 Examples 7

3 View Complete Implementation : filters.py
Copyright Apache License 2.0
Author : bcgov
    def get_form_clast(self):
        """
        Adds a match_any filter to filters.
        """
        real_fields = [
            (name, filter_.field)
            for name, filter_ in self.filters.items()]
        match_any_field = forms.NullBooleanField(label='Match any',
                                                 help_text='If true, match any rather '
                                                 'than all of the filters given.',
                                                 required=False,
                                                 widget=BooleanWidget)
        fields = OrderedDict([('match_any', match_any_field)] + real_fields)

        return type(str('%sForm' % self.__clast__.__name__),
                    (self._meta.form,), fields)

3 View Complete Implementation : __init__.py
Copyright GNU General Public License v2.0
Author : blackye
    def formfield(self, **kwargs):
        defaults = {
            'form_clast': 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)

3 View Complete Implementation : test_nullbooleanfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_nullbooleanfield_clean(self):
        f = NullBooleanField()
        self.astertIsNone(f.clean(''))
        self.astertTrue(f.clean(True))
        self.astertFalse(f.clean(False))
        self.astertIsNone(f.clean(None))
        self.astertFalse(f.clean('0'))
        self.astertTrue(f.clean('1'))
        self.astertIsNone(f.clean('2'))
        self.astertIsNone(f.clean('3'))
        self.astertIsNone(f.clean('hello'))
        self.astertTrue(f.clean('true'))
        self.astertFalse(f.clean('false'))

3 View Complete Implementation : test_nullbooleanfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_nullbooleanfield_2(self):
        # The internal value is preserved if using HiddenInput (#7753).
        clast HiddenNullBooleanForm(Form):
            hidden_nullbool1 = NullBooleanField(widget=HiddenInput, initial=True)
            hidden_nullbool2 = NullBooleanField(widget=HiddenInput, initial=False)
        f = HiddenNullBooleanForm()
        self.astertHTMLEqual(
            '<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)
        )

3 View Complete Implementation : test_nullbooleanfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_nullbooleanfield_3(self):
        clast 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.astertIsNone(f.full_clean())
        self.astertTrue(f.cleaned_data['hidden_nullbool1'])
        self.astertFalse(f.cleaned_data['hidden_nullbool2'])

3 View Complete Implementation : test_nullbooleanfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    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'))

        clast 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.astertIsNone(f.full_clean())
        self.astertTrue(f.cleaned_data['nullbool0'])
        self.astertFalse(f.cleaned_data['nullbool1'])
        self.astertIsNone(f.cleaned_data['nullbool2'])

3 View Complete Implementation : test_nullbooleanfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_nullbooleanfield_changed(self):
        f = NullBooleanField()
        self.astertTrue(f.has_changed(False, None))
        self.astertTrue(f.has_changed(None, False))
        self.astertFalse(f.has_changed(None, None))
        self.astertFalse(f.has_changed(False, False))
        self.astertTrue(f.has_changed(True, False))
        self.astertTrue(f.has_changed(True, None))
        self.astertTrue(f.has_changed(True, False))
        # HiddenInput widget sends string values for boolean but doesn't clean them in value_from_datadict
        self.astertFalse(f.has_changed(False, 'False'))
        self.astertFalse(f.has_changed(True, 'True'))
        self.astertFalse(f.has_changed(None, ''))
        self.astertTrue(f.has_changed(False, 'True'))
        self.astertTrue(f.has_changed(True, 'False'))
        self.astertTrue(f.has_changed(None, 'False'))

3 View Complete Implementation : test_forms.py
Copyright Apache License 2.0
Author : ooknosi
    def test_MaterialForm_materializes_NullBooleanField(self):
        """django.forms.widgets.NullBooleanSelect should be converted to
        material_widgets.widgets.MaterialNullBooleanSelect.
        """

        clast NullBooleanSelectForm(MaterialForm):
            null_boolean_select = forms.NullBooleanField()

        form = NullBooleanSelectForm()
        self.astertEqual(
            type(form.fields['null_boolean_select'].widget),
            widgets.MaterialNullBooleanSelect,
            )

3 View Complete Implementation : filters.py
Copyright MIT License
Author : opennode
def filter_by_accounting_is_running(request, queryset, query):
    if not django_settings.WALDUR_CORE['ENABLE_ACCOUNTING_START_DATE']:
        return queryset

    value = request.query_params.get('accounting_is_running')
    boolean_field = forms.NullBooleanField()

    try:
        value = boolean_field.to_python(value)
    except exceptions.ValidationError:
        value = None

    if value is None:
        return queryset

    if value:
        return queryset.exclude(query)
    else:
        return queryset.filter(query)

3 View Complete Implementation : serializers.py
Copyright MIT License
Author : opennode
    def _add_field_from_initial_data(self, attrs, name):
        param = self.initial_data.get(name)
        boolean_field = forms.NullBooleanField()
        try:
            param = boolean_field.to_python(param)
        except exceptions.ValidationError:
            param = None

        attrs[name] = param

0 View Complete Implementation : converter.py
Copyright MIT License
Author : graphql-python
@convert_form_field.register(forms.NullBooleanField)
def convert_form_field_to_nullboolean(field):
    return Boolean(description=field.help_text)

0 View Complete Implementation : test_converter.py
Copyright MIT License
Author : graphql-python
def test_should_nullboolean_convert_boolean():
    field = astert_conversion(forms.NullBooleanField, Boolean)
    astert not isinstance(field.type, NonNull)

0 View Complete Implementation : test_booleanfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_nullbooleanfield_formfield(self):
        f = models.BooleanField(null=True)
        self.astertIsInstance(f.formfield(), forms.NullBooleanField)
        f = models.NullBooleanField()
        self.astertIsInstance(f.formfield(), forms.NullBooleanField)