本文整理汇总了Python中django.forms.CheckboxSelectMultiple方法的典型用法代码示例。如果您正苦于以下问题:Python forms.CheckboxSelectMultiple方法的具体用法?Python forms.CheckboxSelectMultiple怎么用?Python forms.CheckboxSelectMultiple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms
的用法示例。
在下文中一共展示了forms.CheckboxSelectMultiple方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['emri'].widget.attrs.update({'class': 'form-control'})
# class LendetForm(forms.ModelForm):
# class Meta:
# model = ProvimetMundshme
# fields = '__all__'
# def __init__(self, *args, **kwargs):
# super().__init__(*args, **kwargs)
# self.fields['program'].widget.attrs.update({'class': 'form-control', 'data-type': 'program-listener'})
# self.fields['semester'].widget.attrs.update({'class': 'form-control'})
# self.fields['year'].widget.attrs.update({'class': 'form-control'})
# self.fields['level'].widget.attrs.update({'class': 'form-control'})
# course = forms.MultipleChoiceField(
# widget=forms.CheckboxSelectMultiple,
# choices=[(c.pk, c.name) for c in Course.objects.all()],
# )
示例2: make_entry_field
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def make_entry_field(self, fieldsubmission=None):
the_choices = [(k, v) for k, v in self.config.items() if k.startswith("choice_") and self.config[k]]
the_choices = sorted(the_choices, key=lambda choice: (int) (re.findall(r'\d+', choice[0])[0]))
initial = []
if fieldsubmission:
initial=fieldsubmission.data['info']
c = self.CustomMultipleChoiceField(required=self.config['required'],
label=self.config['label'],
help_text=self.config['help_text'],
choices=the_choices,
widget=forms.CheckboxSelectMultiple(),
initial=initial)
return c
示例3: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, project, *args, **kwargs):
kwargs.setdefault('label_suffix', '')
super(SiteBulkEditForm, self).__init__(*args, **kwargs)
self.fields['sites'] = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
queryset=project.sites.all(),
)
for attr in project.site_meta_attributes:
q_type = attr['question_type']
q_name = attr['question_name']
if q_type == 'Number':
field = forms.FloatField()
elif q_type == 'Date':
field = forms.DateField()
elif q_type == 'MCQ':
options = attr.get('mcq_options') or []
choices = [o.get('option_text') for o in options]
choices = [(c, c) for c in choices]
field = forms.ChoiceField(choices=choices)
else:
field = forms.CharField()
self.fields[q_name] = field
示例4: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
if settings.TARGET_PERMISSIONS_ONLY:
self.common_layout = Layout('facility', 'target_id', 'observation_type')
else:
self.fields['groups'] = forms.ModelMultipleChoiceField(Group.objects.none(),
required=False,
widget=forms.CheckboxSelectMultiple)
self.common_layout = Layout('facility', 'target_id', 'observation_type', 'groups')
self.helper.layout = Layout(
self.common_layout,
self.layout(),
self.button_layout()
)
示例5: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not settings.TARGET_PERMISSIONS_ONLY:
self.fields['groups'] = forms.ModelMultipleChoiceField(Group.objects.none(),
required=False,
widget=forms.CheckboxSelectMultiple)
示例6: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, referral_location_qs, *args, **kwargs):
super(ReferralForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.fields['location'].widget = forms.widgets.CheckboxSelectMultiple()
self.fields['location'].queryset = referral_location_qs
self.helper.add_input(Submit('submit', 'Create referral'))
示例7: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, *args, **kwargs):
settings = kwargs.pop('settings', None)
super(GeneratedPluginSettingForm, self).__init__(*args, **kwargs)
for field in settings:
object = field['object']
if field['types'] == 'char':
self.fields[field['name']] = forms.CharField(widget=forms.TextInput(), required=False)
elif field['types'] == 'rich-text' or field['types'] == 'text' or field['types'] == 'Text':
self.fields[field['name']] = forms.CharField(widget=forms.Textarea, required=False)
elif field['types'] == 'json':
self.fields[field['name']] = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
choices=field['choices'],
required=False)
elif field['types'] == 'number':
self.fields[field['name']] = forms.CharField(widget=forms.TextInput(attrs={'type': 'number'}))
elif field['types'] == 'select':
self.fields[field['name']] = forms.CharField(widget=forms.Select(choices=field['choices']))
elif field['types'] == 'date':
self.fields[field['name']] = forms.CharField(
widget=forms.DateInput(attrs={'class': 'datepicker'}))
elif field['types'] == 'boolean':
self.fields[field['name']] = forms.BooleanField(
widget=forms.CheckboxInput(attrs={'is_checkbox': True}),
required=False)
self.fields[field['name']].initial = object.processed_value
self.fields[field['name']].help_text = object.setting.description
示例8: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['groups'].widget = forms.CheckboxSelectMultiple()
self.fields['groups'].queryset = Group.objects.all()
示例9: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, poll, user=None, *args, **kwargs):
super(PollVoteManyForm, self).__init__(*args, **kwargs)
self.auto_id = 'id_poll_{pk}_%s'.format(pk=poll.pk) # Uniqueness "<label for=id_poll_pk_..."
self.user = user
self.poll = poll
self.poll_choices = getattr(poll, 'choices', poll.poll_choices.unremoved())
choices = ((c.pk, mark_safe(c.description)) for c in self.poll_choices)
if poll.is_multiple_choice:
self.fields['choices'] = forms.MultipleChoiceField(
choices=choices,
widget=forms.CheckboxSelectMultiple,
label=_("Poll choices")
)
else:
self.fields['choices'] = forms.ChoiceField(
choices=choices,
widget=forms.RadioSelect,
label=_("Poll choices")
)
示例10: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, topic, *args, **kwargs):
super(CommentMoveForm, self).__init__(*args, **kwargs)
self.fields['comments'] = forms.ModelMultipleChoiceField(
queryset=Comment.objects.filter(topic=topic),
widget=forms.CheckboxSelectMultiple
)
示例11: test_formfield
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def test_formfield(self):
field = self.get_field(HookSelectModel, "hooks")
formfield = field.formfield()
self.assertTrue(isinstance(formfield, HookMultiSelectFormField))
self.assertTrue(isinstance(formfield.widget, CheckboxSelectMultiple))
self.assertEqual(
formfield.choices,
[("save_form_submission_data", "Save form submission data")],
)
示例12: is_checkbox
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def is_checkbox(boundfield):
"""Return True if this field's widget is a CheckboxInput."""
widget = boundfield.field.widget
is_checkbox_input = isinstance(widget, forms.CheckboxInput)
is_checkbox_select = isinstance(widget, forms.CheckboxSelectMultiple)
return is_checkbox_input or is_checkbox_select
示例13: test_is_checkbox_with_CheckboxSelectMultiple_return_true
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def test_is_checkbox_with_CheckboxSelectMultiple_return_true(mocker):
boundfield = mocker.Mock()
boundfield.field = mocker.Mock()
boundfield.field.widget = forms.CheckboxSelectMultiple()
assert filters.is_checkbox(boundfield)
示例14: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user', None)
super(ProfileForm, self).__init__(*args, **kwargs)
self.fields['full_name'] = forms.CharField(
max_length=30,
initial=self.user.full_name,
widget=forms.TextInput(attrs={
'placeholder': _('Name'),
}),
error_messages={
'required': _('Please enter your full name.')
})
self.fields['bio'] = forms.CharField(
initial=self.user.bio,
widget=forms.Textarea(attrs={
'class': 'bio',
'placeholder': _('Add some details about yourself...'),
'rows': 'auto',
}),
required=False)
roles = Role.objects.all()
self.fields['roles'] = RoleModelMultipleChoiceField(
initial=self.user.roles.all(),
queryset=roles,
widget=forms.CheckboxSelectMultiple(),
required=False)
示例15: test_generates_checkbox
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import CheckboxSelectMultiple [as 别名]
def test_generates_checkbox(self):
field = mocks.MockQuestion(self.question.serialized).make_field()
self.assertEqual(len(field.choices), 5)
self.assertEqual(field.choices[4][1], "This is choice 4")
self.assertIsInstance(field.widget, forms.CheckboxSelectMultiple)