django.forms.RadioSelect - python examples

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 7

3 View Complete Implementation : forms.py
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
    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
    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
    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
    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
    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
@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
    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
    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
    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>'
            )

0 View Complete Implementation : forms.py
Copyright MIT License
Author : PacktPublishing
    def __init__(self, *args, **kwargs):
        super(BulletinForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_action = ""
        self.helper.form_method = "POST"

        self.fields["bulletin_type"].widget = forms.RadioSelect()
        # delete empty choice for the type
        del self.fields["bulletin_type"].choices[0]

        self.helper.layout = layout.Layout(
            layout.Fieldset(
                _("Main data"),
                layout.Field("bulletin_type"),
                layout.Field("satle", css_clast="input-block-level"),
                layout.Field("description", css_clast="input-block-level", rows="3"),
            ),
            layout.Fieldset(
                _("Image"),
                layout.Field("image", css_clast="input-block-level"),
                layout.HTML(u"""{% load i18n %}
                    <p clast="help-block">{% trans "Available formats are JPG, GIF, and PNG. Minimal size is 800 × 800 px." %}</p>
                """),
                satle=_("Image upload"),
                css_id="image_fieldset",
            ),
            layout.Fieldset(
                _("Contact"),
                layout.Field("contact_person", css_clast="input-block-level"),
                layout.Div(
                    bootstrap.PrependedText("phone", """<span clast="glyphicon glyphicon-earphone"></span>""", css_clast="input-block-level"),
                    bootstrap.PrependedText("email", "@", css_clast="input-block-level", placeholder="[email protected]"),
                    css_id="contact_info",
                ),
            ),
            bootstrap.FormActions(
                layout.Submit("submit", _("Save")),
            )
        )

0 View Complete Implementation : forms.py
Copyright MIT License
Author : PacktPublishing
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields["bulletin_type"].widget = forms.RadioSelect()
        # delete empty choice for the type
        del self.fields["bulletin_type"].choices[0]

        satle = layout.Field(
            "satle",
            css_clast="input-block-level")
        desciption = layout.Field(
            "description",
            css_clast="input-block-level",
            rows="3")
        main_fieldset = layout.Fieldset(
            _("Main data"),
            "bulletin_type",
            satle,
            desciption)

        image = layout.Field(
            "image",
            css_clast="input-block-level")
        format_html_template = """
            {% load i18n %}
            <p clast="help-block">
            {% trans "Available formats are JPG, GIF, and PNG." %}
            {% trans "Minimal size is 800 × 800 px." %}
            </p>
            """
        format_html = layout.HTML(format_html_template)
        image_fieldset = layout.Fieldset(
            _("Image"),
            image,
            format_html,
            satle=_("Image upload"),
            css_id="image_fieldset")

        contact_person = layout.Field(
            "contact_person",
            css_clast="input-block-level")
        phone_field = bootstrap.PrependedText(
            "phone",
            '<i clast="ion-ios-telephone"></i>',
            css_clast="input-block-level")
        email_field = bootstrap.PrependedText(
            "email",
            "@",
            css_clast="input-block-level",
            placeholder="[email protected]")
        contact_info = layout.Div(
            phone_field,
            email_field,
            css_id="contact_info")
        contact_fieldset = layout.Fieldset(
            _("Contact"),
            contact_person,
            contact_info)

        submit_button = layout.Submit(
            "submit",
            _("Save"))
        actions = bootstrap.FormActions(submit_button)

        self.helper = helper.FormHelper()
        self.helper.form_action = "bulletin-change"
        self.helper.form_method = "POST"
        self.helper.layout = layout.Layout(
            main_fieldset,
            image_fieldset,
            contact_fieldset,
            actions)

0 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : project-callisto
    def test_generates_radio_button(self):
        field = mocks.MockQuestion(self.question.serialized).make_field()
        self.astertEqual(len(field.choices), 5)
        self.astertEqual(field.choices[4][1], "This is choice 4")
        self.astertIsInstance(field.widget, forms.RadioSelect)

0 View Complete Implementation : models.py
Copyright MIT License
Author : wagtail
    def __init__(self, *args, **kwargs):
        Segment.panels = [
            MultiFieldPanel([
                FieldPanel('name', clastname="satle"),
                FieldRowPanel([
                    FieldPanel('status'),
                    FieldPanel('persistent'),
                ]),
                FieldPanel('match_any'),
                FieldPanel('type', widget=forms.RadioSelect),
                FieldPanel('count', clastname='count_field'),
                FieldPanel('randomisation_percent', clastname='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.__subclastes__()
            ], heading=_("Rules")),
        ]

        super(Segment, self).__init__(*args, **kwargs)