django.forms.MultiWidget - python examples

Here are the examples of the python api django.forms.MultiWidget taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

3 View Complete Implementation : test_clearablefileinput.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_render_as_subwidget(self):
        """A ClearableFileInput as a subwidget of MultiWidget."""
        widget = MultiWidget(widgets=(self.widget,))
        self.check_html(widget, 'myfile', [FakeFieldFile()], html=(
            """
            Currently: <a href="something">something</a>
            <input type="checkbox" name="myfile_0-clear" id="myfile_0-clear_id">
            <label for="myfile_0-clear_id">Clear</label><br>
            Change: <input type="file" name="myfile_0">
            """
        ))

3 View Complete Implementation : test_radioselect.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_render_as_subwidget(self):
        """A RadioSelect as a subwidget of MultiWidget."""
        choices = (('', '------'),) + self.beatles
        self.check_html(MultiWidget([self.widget(choices=choices)]), 'beatle', ['J'], html=(
            """<ul>
            <li><label><input type="radio" name="beatle_0" value=""> ------</label></li>
            <li><label><input checked type="radio" name="beatle_0" value="J"> John</label></li>
            <li><label><input type="radio" name="beatle_0" value="P"> Paul</label></li>
            <li><label><input type="radio" name="beatle_0" value="G"> George</label></li>
            <li><label><input type="radio" name="beatle_0" value="R"> Ringo</label></li>
            </ul>"""
        ))

0 View Complete Implementation : crispy_forms_bulma_field.py
Copyright MIT License
Author : jhotujec
@register.filter
def is_multivalue(field):
    return isinstance(field.field.widget, forms.MultiWidget)

0 View Complete Implementation : widgets.py
Copyright MIT License
Author : SectorLabs
    def get_context(self, name, value, attrs):
        context = super(forms.MultiWidget, self).get_context(name, value, attrs)
        if self.is_localized:
            for widget in self.widgets:
                widget.is_localized = self.is_localized
        # value is a list of values, each corresponding to a widget
        # in self.widgets.
        if not isinstance(value, list):
            value = self.decompress(value)

        final_attrs = context["widget"]["attrs"]
        input_type = final_attrs.pop("type", None)
        id_ = final_attrs.get("id")
        subwidgets = []
        for i, widget in enumerate(self.widgets):
            if input_type is not None:
                widget.input_type = input_type
            widget_name = "%s_%s" % (name, i)
            try:
                widget_value = value[i]
            except IndexError:
                widget_value = None
            if id_:
                widget_attrs = final_attrs.copy()
                widget_attrs["id"] = "%s_%s" % (id_, i)
            else:
                widget_attrs = final_attrs
            widget_attrs = self.build_widget_attrs(
                widget, widget_value, widget_attrs
            )
            widget_context = widget.get_context(
                widget_name, widget_value, widget_attrs
            )["widget"]
            widget_context.update(
                dict(lang_code=widget.lang_code, lang_name=widget.lang_name)
            )
            subwidgets.append(widget_context)
        context["widget"]["subwidgets"] = subwidgets
        return context