当前位置: 首页>>代码示例>>Python>>正文


Python forms.BooleanField方法代码示例

本文整理汇总了Python中django.forms.BooleanField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.BooleanField方法的具体用法?Python forms.BooleanField怎么用?Python forms.BooleanField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms的用法示例。


在下文中一共展示了forms.BooleanField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def __init__(self, league, player, *args, **kwargs):
        super(NotificationsForm, self).__init__(*args, **kwargs)
        for type_, _ in PLAYER_NOTIFICATION_TYPES:
            setting = PlayerNotificationSetting.get_or_default(player=player, league=league,
                                                               type=type_)
            self.fields[type_ + "_lichess"] = forms.BooleanField(required=False, label="Lichess",
                                                                 initial=setting.enable_lichess_mail)
            self.fields[type_ + "_slack"] = forms.BooleanField(required=False, label="Slack",
                                                               initial=setting.enable_slack_im)
            self.fields[type_ + "_slack_wo"] = forms.BooleanField(required=False,
                                                                  label="Slack (with opponent)",
                                                                  initial=setting.enable_slack_mpim)
            if type_ == 'before_game_time':
                offset_options = [(5, '5 minutes'), (10, '10 minutes'), (20, '20 minutes'),
                                  (30, '30 minutes'), (60, '1 hour'), (120, '2 hours')]
                self.fields[type_ + '_offset'] = forms.TypedChoiceField(choices=offset_options,
                                                                        initial=int(
                                                                            setting.offset.total_seconds()) / 60,
                                                                        coerce=int) 
开发者ID:cyanfish,项目名称:heltour,代码行数:21,代码来源:forms.py

示例2: set_choices

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def set_choices(self, family):
        # There's probably a better way of doing this
        board_choices = [(brd.id, brd.name) for brd in Board.objects.filter(family=family)]

        self.fields['board_type'].choices = board_choices


# class GuidedDeviceFlashForm(forms.Form):
#     DEVICE_FAMILY_CHOICES = GuidedDeviceSelectForm.DEVICE_FAMILY_CHOICES
#
#     device_family = forms.ChoiceField(label="Device Family",
#                                       widget=forms.Select(attrs={'class': 'form-control',
#                                                                  'data-toggle': 'select'}),
#                                       choices=DEVICE_FAMILY_CHOICES, required=True)
#     should_flash_device = forms.BooleanField(widget=forms.HiddenInput, required=False, initial=False)
#
# 
开发者ID:thorrak,项目名称:fermentrack,代码行数:19,代码来源:forms.py

示例3: get_field_kind

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def get_field_kind(field):
  if field['kind'] == 'string':
    return forms.CharField(max_length=255, required=False)
  elif field['kind'] == 'email':
    return forms.EmailField(max_length=255, required=False)
  elif field['kind'] == 'integer':
    return forms.IntegerField(required=False)
  elif field['kind'] == 'boolean':
    return forms.BooleanField(required=False)
  elif field['kind'] == 'text':
    return forms.CharField(widget=forms.Textarea(), required=False)
  elif field['kind'] == 'choice':
    return forms.ChoiceField(choices=map(lambda c: (c,c), field['choices']))
  elif field['kind'] == 'timezones':
    return TimezoneField()
  elif field['kind'] == 'authentication':
    return SwitchField('user', 'service', required=True)
  elif field['kind'] == 'json':
    return JsonField(required=False)
  elif field['kind'] == 'integer_list':
    return CommaSeparatedIntegerField(required=False)
  elif field['kind'] == 'string_list':
    return CommaSeparatedCharField(required=False)
  else:
    return forms.CharField(max_length=255, required=False) 
开发者ID:google,项目名称:starthinker,代码行数:27,代码来源:forms_json.py

示例4: to_python

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def to_python(self, value):
        """Returns a Python boolean object.

        It is necessary to customize the behavior because the default
        ``BooleanField`` treats the string '0' as ``False``, but if the
        unit is in ``UNTRANSLATED`` state (which would report '0' as a
        value), we need the marked checkbox to be evaluated as ``True``.

        :return: ``False`` for any unknown :cls:`~pootle_store.models.Unit`
            states and for the 'False' string.
        """
        truthy_values = (str(s) for s in (UNTRANSLATED, FUZZY, TRANSLATED))
        if isinstance(value, str) and (
            value.lower() == "false" or value not in truthy_values
        ):
            value = False
        else:
            value = bool(value)

        return super().to_python(value) 
开发者ID:evernote,项目名称:zing,代码行数:22,代码来源:forms.py

示例5: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        field_order = [
            "virtual_server", "name",
            "allow_pairing", "is_supervised", "is_mandatory", "is_mdm_removable",
            "await_device_configured", "auto_advance_setup",
            "support_phone_number", "support_email_address",
            "org_magic", "department", "include_tls_certificates"
        ]
        for pane, initial in self.Meta.model.SKIPPABLE_SETUP_PANES:
            if self.instance.pk:
                initial = pane in self.instance.skip_setup_items
            self.fields[pane] = forms.BooleanField(label="Skip {} pane".format(pane), initial=initial, required=False)
            field_order.append(pane)
        field_order.extend(["realm", "use_realm_user", "realm_user_is_admin",
                            "admin_full_name", "admin_short_name", "admin_password"])
        self.order_fields(field_order) 
开发者ID:zentralopensource,项目名称:zentral,代码行数:19,代码来源:forms.py

示例6: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def __init__(self, extension, *args, **kwargs):
        self.extension = extension
        kwargs.setdefault('label', extension.name)
        ext = profile.extensions.get(self.extension.key)
        if ext:
            ext = ext.serialize()
            kwargs.setdefault('initial', [ext['value'], ext['critical']])

        fields = (
            forms.MultipleChoiceField(required=False, choices=extension.CHOICES),
            forms.BooleanField(required=False),
        )

        widget = MultiValueExtensionWidget(choices=extension.CHOICES)
        super(MultiValueExtensionField, self).__init__(
            fields=fields, require_all_fields=False, widget=widget,
            *args, **kwargs) 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:19,代码来源:fields.py

示例7: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def __init__(self, *args, **kwargs):
        super(ConfigForm, self).__init__(*args, **kwargs)
        self.fields['form_name'] = forms.CharField(initial=self.id, widget=forms.widgets.HiddenInput)
        for option in self.options:
            if option['type'] == "boolean":
                self.fields[option['name']] = forms.BooleanField(
                    label=option['label'],
                    help_text=option['help_text'],
                    initial=option['initial'], required=False)
            if option['type'] == "choice":
                choices = option['choices']
                self.fields[option['name']] = forms.ChoiceField(
                    label=option['label'],
                    help_text=option['help_text'],
                    choices = list(zip(list(range(len(choices))), choices)),
                    initial=option['initial'], required=False)
            elif option['type'] == "text":
                self.fields[option['name']] = forms.CharField(
                    label=option['label'],
                    help_text=option['help_text'],
                    initial=option['initial'], required=False) 
开发者ID:allo-,项目名称:firefox-profilemaker,代码行数:23,代码来源:forms.py

示例8: test_editor_optional_fields_match_field_type

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def test_editor_optional_fields_match_field_type(self):
        """
        The optional user data fields on Editor should correspond to the
        FIELD_TYPES used on the application form. Additionally, each should
        allow blank=True (since not all instances require all data), except for
        BooleanFields, which should default False (i.e. they should default to
        not requiring the data).
        """
        for field in USER_FORM_FIELDS:
            # Ensure Editor fields allow for empty data.
            if not isinstance(Editor._meta.get_field(field), models.BooleanField):
                self.assertTrue(Editor._meta.get_field(field).blank)
            else:
                self.assertFalse(Editor._meta.get_field(field).default)

            # Make sure the form fields we're using match what the model fields
            # can record.
            modelfield = Editor._meta.get_field(field)
            formfield = modelfield.formfield()

            self.assertEqual(type(formfield), type(FIELD_TYPES[field])) 
开发者ID:WikipediaLibrary,项目名称:TWLight,代码行数:23,代码来源:tests.py

示例9: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def __init__(self, *args, **kwargs):
        super(SubscribeForm, self).__init__(*args, **kwargs)

        # error message for existing mail address
        self.fields['email'].error_messages['unique'] = _("You subscribed already to the newsletter.")

        # privacy statement
        privacy_label = format_html(
            '{} (<a href="" data-toggle="collapse" data-target="#privacy">{}</a>)',
            _("I agree with the data privacy statement."),
            _("Show"),
        )
        privacy_error = _("You have to accept the data privacy statement.")

        self.fields['privacy_statement'] = forms.BooleanField(
            label=privacy_label,
            required=True,
            error_messages={'required': privacy_error},
        ) 
开发者ID:helfertool,项目名称:helfertool,代码行数:21,代码来源:subscribe.py

示例10: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def __init__(self, with_wysiwyg=False, rows=20, default_markup='creole', allow_math=True, restricted=False,
                 max_length=100000, required=True, *args, **kwargs):
        choices = MARKUP_CHOICES_WYSIWYG if with_wysiwyg else MARKUP_CHOICES
        fields = [
            forms.CharField(required=required, max_length=max_length),
            forms.ChoiceField(choices=choices, required=True),
            forms.BooleanField(required=False),
        ]
        self.required = required
        self.force_display_required = required

        help_url = '/docs/markup' # hard-coded URL because lazy-evaluating them is hard
        default_help = '<a href="' + help_url + '">Markup language</a> used in the content'
        if allow_math:
            default_help += ', and should <a href="http://www.mathjax.org/">MathJax</a> be used for displaying TeX formulas?'
        default_help += ' <span id="markup-help"></span>'
        help_text = kwargs.pop('help_text', mark_safe(default_help))

        super(MarkupContentField, self).__init__(fields, required=False,
            help_text=help_text,
            *args, **kwargs)

        self.fields[0].required = required
        self.widget.widgets[0].attrs['rows'] = rows
        self.fields[1].required = required
        self.widget.widgets[1].choices = choices

        self.widget.allow_math = allow_math
        self.restricted = restricted
        self.widget.default_markup = default_markup 
开发者ID:sfu-fas,项目名称:coursys,代码行数:32,代码来源:markup.py

示例11: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def __init__(self, *args, **kwargs):
        kwargs['blank'] = True
        super(BooleanField, self).__init__(*args, **kwargs) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:5,代码来源:__init__.py

示例12: check

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def check(self, **kwargs):
        errors = super(BooleanField, self).check(**kwargs)
        errors.extend(self._check_null(**kwargs))
        return errors 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:__init__.py

示例13: deconstruct

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def deconstruct(self):
        name, path, args, kwargs = super(BooleanField, self).deconstruct()
        del kwargs['blank']
        return name, path, args, kwargs 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:__init__.py

示例14: get_internal_type

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
def get_internal_type(self):
        return "BooleanField" 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:4,代码来源:__init__.py

示例15: get_prep_lookup

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import BooleanField [as 别名]
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(BooleanField, self).get_prep_lookup(lookup_type, value) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:10,代码来源:__init__.py


注:本文中的django.forms.BooleanField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。