當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。