• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

goinnn / django-multiselectfield / 15554860122

10 Jun 2025 08:44AM UTC coverage: 87.85% (+0.4%) from 87.5%
15554860122

Pull #173

github

web-flow
Merge 86374eb5f into 9a084705f
Pull Request #173: Fix CSS Styling for Checkbox in MultiSelectField Widget

13 of 13 new or added lines in 2 files covered. (100.0%)

4 existing lines in 1 file now uncovered.

188 of 214 relevant lines covered (87.85%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.64
/multiselectfield/forms/widgets.py
1
# -*- coding: utf-8 -*-
2
# Copyright (c) 2012 by Pablo Martín <goinnn@gmail.com>
3
#
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU Lesser General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Lesser General Public License for more details.
13
#
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with this programe.  If not, see <https://www.gnu.org/licenses/>.
16
import sys
1✔
17

18
from django import forms
1✔
19

20

21
class MultiSelectCheckboxSelectMultiple(forms.CheckboxSelectMultiple):
1✔
22

23
    class Media:
1✔
24
        css = {
1✔
25
            'all': ('multiselectfield/css/multiselectfield.css',)
26
        }
27

28
    def __init__(self, *args, **kwargs):
1✔
29
        super().__init__(*args, **kwargs)
1✔
30

31
        self.attrs['class'] = 'multiselectfield'
1✔
32

33

34
class SortedCheckboxSelectMultiple(forms.CheckboxSelectMultiple):
1✔
35

36
    def __init__(self, *args, **kwargs):
1✔
37
        super().__init__(*args, **kwargs)
1✔
38
        self.attrs['class'] = 'multiselectfield ui-pre-sortable'
1✔
39

40
    class Media:
1✔
41
        js = (
1✔
42
            'sortmultiselectfield/sortmultiselectfield.js'
43
        )
44
        css = {
1✔
45
            'all': (
46
                'multiselectfield/css/multiselectfield.css',
47
                'sortmultiselectfield/sortmultiselectfield.css',
48
            )
49
        }
50

51
    def optgroups(self, name, value, attrs=None):
1✔
52
        """Return a list of optgroups for this widget."""
53
        groups = []
1✔
54
        has_selected = False
1✔
55
        choices = self.choices
1✔
56

57
        def index_of(val, in_list):
1✔
58
            try:
1✔
59
                return in_list.index(val)
1✔
60
            except ValueError:
1✔
61
                return sys.maxsize
1✔
62

63
        choices = sorted(choices, key=lambda choice: index_of(choice[0], value))
1✔
64

65
        for index, (option_value, option_label) in enumerate(choices):
1✔
66
            if option_value is None:
1✔
UNCOV
67
                option_value = ''
×
68
            subgroup = []
1✔
69
            if isinstance(option_label, (list, tuple)):
1✔
UNCOV
70
                group_name = option_value
×
UNCOV
71
                subindex = 0
×
72
                choices = option_label
×
73
            else:
74
                group_name = None
1✔
75
                subindex = None
1✔
76
                choices = [(option_value, option_label)]
1✔
77
            groups.append((group_name, subgroup, index))
1✔
78

79
            for subvalue, sublabel in choices:
1✔
80
                selected = (not has_selected or self.allow_multiple_selected) and str(
1✔
81
                    subvalue
82
                ) in value
83
                has_selected |= selected
1✔
84
                subgroup.append(
1✔
85
                    self.create_option(
86
                        name,
87
                        subvalue,
88
                        sublabel,
89
                        selected,
90
                        index,
91
                        subindex=subindex,
92
                        attrs=attrs,
93
                    )
94
                )
95
                if subindex is not None:
1✔
UNCOV
96
                    subindex += 1
×
97
        return groups
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc