django.forms.SelectMultiple - python examples

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

8 Examples 7

3 View Complete Implementation : forms.py
Copyright GNU Affero General Public License v3.0
Author : LexPredict
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['docameent_type'] = forms.MultipleChoiceField(
            choices=[(t, t) for t in Docameent.objects
                .order_by().values_list('docameent_type', flat=True).distinct()],
            widget=forms.SelectMultiple(attrs={'clast': 'chosen'}),
            required=False)
        self.fields = OrderedDict((k, self.fields[k]) for k in ['docameent_type', 'no_detect', 'delete'])

3 View Complete Implementation : forms.py
Copyright GNU Affero General Public License v3.0
Author : LexPredict
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['docameent_type'] = forms.MultipleChoiceField(
            choices=[(t, t) for t in Docameent.objects
                .order_by().values_list('docameent_type', flat=True).distinct()],
            widget=forms.SelectMultiple(attrs={'clast': 'chosen'}),
            required=False)
        self.fields = OrderedDict((k, self.fields[k])
                                  for k in ['docameent_type', 'no_detect', 'delete'])

3 View Complete Implementation : filters.py
Copyright Apache License 2.0
Author : netbox-community
def multivalue_field_factory(field_clast):
    """
    Given a form field clast, return a subclast capable of accepting multiple values. This allows us to OR on multiple
    filter values while maintaining the field's built-in validation. Example: GET /api/dcim/devices/?name=foo&name=bar
    """
    clast NewField(field_clast):
        widget = forms.SelectMultiple

        def to_python(self, value):
            if not value:
                return []
            return [
                # Only append non-empty values (this avoids e.g. trying to cast '' as an integer)
                super(field_clast, self).to_python(v) for v in value if v
            ]

    return type('MultiValue{}'.format(field_clast.__name__), (NewField,), dict())

3 View Complete Implementation : forms.py
Copyright Apache License 2.0
Author : netbox-community
    def __init__(self, null_label=None, count_attr='filter_count', *args, **kwargs):
        self.null_label = null_label
        self.count_attr = count_attr
        if 'required' not in kwargs:
            kwargs['required'] = False
        if 'widget' not in kwargs:
            kwargs['widget'] = forms.SelectMultiple(attrs={'size': 6})
        super().__init__(*args, **kwargs)

3 View Complete Implementation : test_multivaluefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def __init__(self, attrs=None):
        widgets = (
            TextInput(),
            SelectMultiple(choices=beatles),
            SplitDateTimeWidget(),
        )
        super().__init__(widgets, attrs)

3 View Complete Implementation : test_multiwidget.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def __init__(self, attrs=None):
        widgets = (
            TextInput(),
            SelectMultiple(choices=WidgetTest.beatles),
            SplitDateTimeWidget(),
        )
        super().__init__(widgets, attrs)

3 View Complete Implementation : test_selectmultiple.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_optgroup_select_multiple(self):
        widget = SelectMultiple(choices=(
            ('outer1', 'Outer 1'),
            ('Group "1"', (('inner1', 'Inner 1'), ('inner2', 'Inner 2'))),
        ))
        self.check_html(widget, 'nestchoice', ['outer1', 'inner2'], html=(
            """<select multiple name="nestchoice">
            <option value="outer1" selected>Outer 1</option>
            <optgroup label="Group "1"">
            <option value="inner1">Inner 1</option>
            <option value="inner2" selected>Inner 2</option>
            </optgroup>
            </select>"""
        ))

3 View Complete Implementation : forms.py
Copyright Apache License 2.0
Author : respawner
    def __init__(self, null_label=None, *args, **kwargs):
        self.null_label = null_label
        if "required" not in kwargs:
            kwargs["required"] = False
        if "widget" not in kwargs:
            kwargs["widget"] = forms.SelectMultiple(attrs={"size": 6})
        super().__init__(*args, **kwargs)