Here are the examples of the python api django.forms.RadioSelect taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
14 Examples
3
View Complete Implementation : forms.py
Copyright Apache License 2.0
Author : chrisjrn
Copyright Apache License 2.0
Author : chrisjrn
@clastmethod
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,
)
3
View Complete Implementation : duplicates.py
Copyright GNU Affero General Public License v3.0
Author : helfertool
Copyright GNU Affero General Public License v3.0
Author : helfertool
def __init__(self, *args, **kwargs):
self._helpers = kwargs.pop('helpers')
super(MergeDuplicatesForm, self).__init__(*args, **kwargs)
self.fields['helpers'] = forms.ModelChoiceField(
queryset=self._helpers,
widget=forms.RadioSelect(attrs={'id': 'helper'}),
empty_label=None,
required=True,
label='')
3
View Complete Implementation : forms.py
Copyright Mozilla Public License 2.0
Author : mozilla
Copyright Mozilla Public License 2.0
Author : mozilla
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", "clast": "radioset"}
),
help_text=models.Cluster.EMR_RELEASE_HELP,
)
3
View Complete Implementation : test_nullbooleanfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_multiwidget.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def __init__(self, choices=[]):
widgets = [
RadioSelect(choices=choices),
TextInput,
]
super().__init__(widgets)
3
View Complete Implementation : test_radioselect.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_constructor_attrs(self):
"""
Attributes provided at instantiation are pasted to the conssatuent
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)
0
View Complete Implementation : crispy_forms_bulma_field.py
Copyright MIT License
Author : jhotujec
Copyright MIT License
Author : jhotujec
@register.filter
def is_radioselect(field):
return isinstance(field.field.widget, forms.RadioSelect)
0
View Complete Implementation : forms.py
Copyright GNU Affero General Public License v3.0
Author : liqd
Copyright GNU Affero General Public License v3.0
Author : liqd
def __init__(self, user=None, organisation=None, *args, **kwargs):
super().__init__(*args, **kwargs)
choices = [(value, string)
for value, string in models.RECEIVER_CHOICES
if value != models.PLATFORM or (user and user.is_superuser)]
self.fields['receivers'] = forms.ChoiceField(
label=_('Receivers'),
choices=choices,
widget=forms.RadioSelect(),
)
project_qs = Project.objects
if organisation:
project_qs = Project.objects.filter(organisation=organisation.id)
self.fields['project'] = forms.ModelChoiceField(
label=_('Project'),
queryset=project_qs,
required=False, empty_label=None)
self.fields['organisation'] = forms.ModelChoiceField(
label=_('Organisation'),
queryset=Organisation.objects,
required=False, empty_label=None)
0
View Complete Implementation : forms.py
Copyright Mozilla Public License 2.0
Author : mozilla
Copyright Mozilla Public License 2.0
Author : mozilla
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
user_sshkeys = self.created_by.created_sshkeys.all()
self.fields["ssh_key"].queryset = user_sshkeys.all()
self.fields["ssh_key"].help_text = (
"The SSH key to deploy to the cluster. "
'See <a href="%s">your keys</a> or '
'<a href="%s">add a new one</a>.'
% (reverse("keys-list"), reverse("keys-new"))
)
# if the user is not a cluster maintainer, reset the max
# to the default so they can't create larger clusters
if not self.created_by.has_perm("clusters.maintain_cluster"):
max_size = settings.AWS_CONFIG["MAX_CLUSTER_SIZE"]
self.fields["size"].max_value = max_size
self.fields["size"].validators.append(
validators.MaxValueValidator(max_size)
)
self.fields["size"].widget.attrs["max"] = max_size
self.fields["size"].help_text = (
"Number of workers to use in the cluster, between 1 and %s. "
"For testing or development 1 is recommended." % max_size
)
# if there are fewer options we just show radio select buttons
if user_sshkeys.count() <= 6:
self.fields["ssh_key"].widget = forms.RadioSelect(
choices=self.fields["ssh_key"].choices, attrs={"clast": "radioset"}
)
0
View Complete Implementation : test_i18n.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_non_ascii_choices(self):
clast SomeForm(Form):
somechoice = ChoiceField(
choices=(('\xc5', 'En tied\xe4'), ('\xf8', 'Mies'), ('\xdf', 'Nainen')),
widget=RadioSelect(),
label='\xc5\xf8\xdf',
)
f = SomeForm()
self.astertHTMLEqual(
f.as_p(),
'<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label>'
'<ul id="id_somechoice">\n'
'<li><label for="id_somechoice_0">'
'<input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" required> '
'En tied\xe4</label></li>\n'
'<li><label for="id_somechoice_1">'
'<input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" required> '
'Mies</label></li>\n<li><label for="id_somechoice_2">'
'<input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" required> '
'Nainen</label></li>\n</ul></p>'
)
# Translated error messages
with translation.override('ru'):
f = SomeForm({})
self.astertHTMLEqual(
f.as_p(),
'<ul clast="errorlist"><li>'
'\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c'
'\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n'
'<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label>'
' <ul id="id_somechoice">\n<li><label for="id_somechoice_0">'
'<input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" required> '
'En tied\xe4</label></li>\n'
'<li><label for="id_somechoice_1">'
'<input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" required> '
'Mies</label></li>\n<li><label for="id_somechoice_2">'
'<input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" required> '
'Nainen</label></li>\n</ul></p>'
)