本文整理汇总了Python中django.forms.RadioSelect方法的典型用法代码示例。如果您正苦于以下问题:Python forms.RadioSelect方法的具体用法?Python forms.RadioSelect怎么用?Python forms.RadioSelect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms
的用法示例。
在下文中一共展示了forms.RadioSelect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
custom_widgets = [forms.CheckboxInput, forms.RadioSelect]
for field_name, field in self.fields.items():
if field.widget.__class__ in custom_widgets:
css = field.widget.attrs.get("class", "")
field.widget.attrs["class"] = " ".join(
[css, "custom-control-input"]
).strip()
else:
css = field.widget.attrs.get("class", "")
field.widget.attrs["class"] = " ".join([css, "form-control"]).strip()
if field.required:
field.widget.attrs["required"] = "required"
if "placeholder" not in field.widget.attrs:
field.widget.attrs["placeholder"] = field.label
示例2: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
Segment.panels = [
MultiFieldPanel([
FieldPanel('name', classname="title"),
FieldRowPanel([
FieldPanel('status'),
FieldPanel('persistent'),
]),
FieldPanel('match_any'),
FieldPanel('type', widget=forms.RadioSelect),
FieldPanel('count', classname='count_field'),
FieldPanel('randomisation_percent', classname='percent_field'),
], heading="Segment"),
MultiFieldPanel([
RulePanel(
"{}_related".format(rule_model._meta.db_table),
label='{}{}'.format(
rule_model._meta.verbose_name,
' ({})'.format(_('Static compatible')) if rule_model.static else ''
),
) for rule_model in AbstractBaseRule.__subclasses__()
], heading=_("Rules")),
]
super(Segment, self).__init__(*args, **kwargs)
示例3: set_fields
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def set_fields(cls, category, products):
choices = []
for product in products:
choice_text = "%s -- $%d" % (product.name, product.price)
choices.append((product.id, choice_text))
if not category.required:
choices.append((0, "No selection"))
cls.base_fields[cls.FIELD] = forms.TypedChoiceField(
label=category.name,
widget=forms.RadioSelect,
choices=choices,
empty_value=0,
coerce=int,
)
示例4: test_constructor_attrs
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def test_constructor_attrs(self):
"""
Attributes provided at instantiation are passed to the constituent
inputs.
"""
widget = RadioSelect(attrs={'id': 'foo'}, choices=self.beatles)
html = """
<ul id="foo">
<li>
<label for="foo_0"><input checked type="radio" id="foo_0" value="J" name="beatle"> John</label>
</li>
<li><label for="foo_1"><input type="radio" id="foo_1" value="P" name="beatle"> Paul</label></li>
<li><label for="foo_2"><input type="radio" id="foo_2" value="G" name="beatle"> George</label></li>
<li><label for="foo_3"><input type="radio" id="foo_3" value="R" name="beatle"> Ringo</label></li>
</ul>
"""
self.check_html(widget, 'beatle', 'J', html=html)
示例5: populate_questions_inputs
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def populate_questions_inputs(self, survey, question_group_id, **kwargs):
questions_qs = survey.get_questions().filter(
question_group__id=question_group_id
).order_by('order',)
for question in questions_qs:
if not question.is_active:
# skip inactive questions
continue
qid = question.qid
self.fields[qid] = forms.CharField(label=question.text)
if question.question_type == Question.RADIO:
self.fields[qid].widget = forms.RadioSelect(choices=self.CHOICES_1_10)
elif question.question_type == Question.BOOLEAN:
self.fields[qid] = forms.BooleanField(label=question.text)
elif question.question_type == Question.TEXT:
pass # non modifica niente
示例6: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Per indicare con request.POST con che form/step stiamo lavorando
self.fields['step'].initial = self.step
# Risposte precedentemente salvate
response_lezioni = self.survey_result.response_json['utilita_lezioni']
# for lezione in self.course.get_lezioni_precaricate():
for lezione in self.course.lezioni.all():
lezione_pk = 'lezioni_pk_%s' % lezione.pk
# Crea i campi con 10 radio-button (0-10)
self.fields[lezione_pk] = forms.CharField(label=lezione.nome)
self.fields[lezione_pk].widget = forms.RadioSelect(choices=self.CHOICES_1_10)
# Valorizzare gli input se ci sono le risposte
lezione_pk_str = str(lezione.pk)
if lezione_pk_str in response_lezioni:
self.fields[lezione_pk].initial = response_lezioni[lezione_pk_str]
示例7: is_radio
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def is_radio(field):
return isinstance(field.field.widget, forms.RadioSelect)
示例8: get_entry_field
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def get_entry_field(self, questionanswer=None, student=None):
options = self.version.config.get('options', [])
permute = self.version.config.get('permute', 'keep')
show_no_answer = self.version.config.get('show_no_answer', 'noshow')
if questionanswer:
initial = questionanswer.answer.get('data', MultipleChoice.NA)
else:
initial = MultipleChoice.NA
options = list(enumerate(options)) # keep original positions so the input values match that, but students see a possibly-randomized order
if student and permute == 'permute':
rand = self.question.quiz.random_generator(str(student.id) + '-' + str(self.question.id) + '-' + str(self.version.id))
options = rand.permute(options)
elif student and permute == 'not-last':
rand = self.question.quiz.random_generator(str(student.id) + '-' + str(self.question.id) + '-' + str(self.version.id))
last = options[-1]
options = rand.permute(options[:-1])
options.append(last)
choices = [
(OPTION_LETTERS[opos], mark_safe('<span class="mc-letter">' + OPTION_LETTERS[i] + '.</span> ') + escape(o[0]))
for i, (opos, o)
in enumerate(options)
]
if show_no_answer == 'show':
choices.append((MultipleChoice.NA, 'no answer'))
field = forms.ChoiceField(required=False, initial=initial, choices=choices, widget=forms.RadioSelect())
field.widget.attrs.update({'class': 'multiple-choice'})
return field
示例9: make_entry_field
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [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]))
c = forms.ChoiceField(required=self.config['required'],
label=self.config['label'],
help_text=self.config['help_text'],
choices=the_choices,
widget=forms.RadioSelect())
if fieldsubmission:
initial=fieldsubmission.data['info']
c.initial=initial
return c
示例10: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(
label="EMR release",
queryset=models.EMRRelease.objects.active().natural_sort_by_version(),
required=True,
empty_label=None,
widget=forms.RadioSelect(
attrs={"required": "required", "class": "radioset"}
),
help_text=models.Cluster.EMR_RELEASE_HELP,
)
示例11: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
super(ProposalVoteForm, self).__init__(*args, **kwargs)
# Use a radio select widget instead of a dropdown for the score.
self.fields["score"] = forms.TypedChoiceField(
choices=ProposalVote.SCORES,
coerce=int,
empty_value=0,
widget=forms.RadioSelect(),
)
示例12: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, has_recurrences, *args, **kwargs):
super(DeleteScheduleForm, self).__init__(*args, **kwargs)
if has_recurrences:
choices = (
(self.DELETE_ONLY_THIS, 'Only this instance'),
(self.DELETE_THIS_AND_FOLLOWING, 'This and all the following events'),
(self.DELETE_ALL, 'All events in the series'),
)
self.fields['action'] = forms.ChoiceField(choices=choices, label='', help_text='', widget=forms.RadioSelect)
示例13: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [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")
)
示例14: test_generates_radio_button
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def test_generates_radio_button(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.RadioSelect)
示例15: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import RadioSelect [as 别名]
def __init__(self, *args, **kwargs):
"""
Add custom handling for requested_sources and override some widgets.
"""
super().__init__(*args, **kwargs)
source_projects = DataRequestProject.objects.filter(approved=True).exclude(
returned_data_description=""
)
self.fields["requested_sources"].choices = [
(p.id, p.name) for p in source_projects
]
self.fields["requested_sources"].widget = forms.CheckboxSelectMultiple()
self.fields["requested_sources"].required = False
override_fields = [
"is_study",
"is_academic_or_nonprofit",
"active",
"request_username_access",
]
# XXX: feels like a hack; ideally we could just override the widget in
# the Meta class but it doesn't work (you end up with an empty option)
for field in override_fields:
# set the widget to a RadioSelect
self.fields[field].widget = forms.RadioSelect()
# filter out the empty choice
self.fields[field].choices = [
choice for choice in self.fields[field].choices if choice[0] != ""
]
# coerce the result to a boolean
self.fields[field].coerce = lambda x: x == "True"