Beispiel #1
0
    def test_optgroups(self):
        widget = widgets.FilteredSelect(choices=[
            (None, '----'),
            ('Big countries', [
                ('FR', 'France', ['EU']),
                ('JP', 'Japan', ['AS']),
                ('RU', 'Russia', ['AS', 'EU']),
                ('MOON', 'The moon'),
            ]),
            ('Small countries', [
                ('AZ', 'Azerbaijan', ['AS']),
                ('LI', 'Liechtenstein', ['EU']),
            ]), ('SK', 'Slovakia', ['EU'])
        ],
                                        filter_field='id_continent')

        html = widget.render('country', 'JP')
        self.assertHTMLEqual(
            html, '''
            <select name="country" data-widget="filtered-select" data-filter-field="id_continent">
                <option value="">----</option>
                <optgroup label="Big countries">
                    <option value="FR" data-filter-value="EU">France</option>
                    <option value="JP" selected data-filter-value="AS">Japan</option>
                    <option value="RU" data-filter-value="AS,EU">Russia</option>
                    <option value="MOON">The moon</option>
                </optgroup>
                <optgroup label="Small countries">
                    <option value="AZ" data-filter-value="AS">Azerbaijan</option>
                    <option value="LI" data-filter-value="EU">Liechtenstein</option>
                </optgroup>
                <option value="SK" data-filter-value="EU">Slovakia</option>
            </select>
        ''')
Beispiel #2
0
    def test_render(self):
        widget = widgets.FilteredSelect(choices=[
            (None, '----'),
            ('FR', 'France', ['EU']),
            ('JP', 'Japan', ['AS']),
            ('RU', 'Russia', ['AS', 'EU']),
        ], filter_field='id_continent')

        html = widget.render('country', 'JP')
        self.assertHTMLEqual(html, '''
            <select name="country" data-widget="filtered-select" data-filter-field="id_continent">
                <option value="">----</option>
                <option value="FR" data-filter-value="EU">France</option>
                <option value="JP" selected data-filter-value="AS">Japan</option>
                <option value="RU" data-filter-value="AS,EU">Russia</option>
            </select>
        ''')
Beispiel #3
0
    def test_optgroups(self):
        widget = widgets.FilteredSelect(
            choices=[
                (None, "----"),
                (
                    "Big countries",
                    [
                        ("FR", "France", ["EU"]),
                        ("JP", "Japan", ["AS"]),
                        ("RU", "Russia", ["AS", "EU"]),
                        ("MOON", "The moon"),
                    ],
                ),
                (
                    "Small countries",
                    [
                        ("AZ", "Azerbaijan", ["AS"]),
                        ("LI", "Liechtenstein", ["EU"]),
                    ],
                ),
                ("SK", "Slovakia", ["EU"]),
            ],
            filter_field="id_continent",
        )

        html = widget.render("country", "JP")
        self.assertHTMLEqual(
            html,
            """
            <select name="country" data-widget="filtered-select" data-filter-field="id_continent">
                <option value="">----</option>
                <optgroup label="Big countries">
                    <option value="FR" data-filter-value="EU">France</option>
                    <option value="JP" selected data-filter-value="AS">Japan</option>
                    <option value="RU" data-filter-value="AS,EU">Russia</option>
                    <option value="MOON">The moon</option>
                </optgroup>
                <optgroup label="Small countries">
                    <option value="AZ" data-filter-value="AS">Azerbaijan</option>
                    <option value="LI" data-filter-value="EU">Liechtenstein</option>
                </optgroup>
                <option value="SK" data-filter-value="EU">Slovakia</option>
            </select>
        """,
        )
Beispiel #4
0
    def test_render(self):
        widget = widgets.FilteredSelect(
            choices=[
                (None, "----"),
                ("FR", "France", ["EU"]),
                ("JP", "Japan", ["AS"]),
                ("RU", "Russia", ["AS", "EU"]),
            ],
            filter_field="id_continent",
        )

        html = widget.render("country", "JP")
        self.assertHTMLEqual(
            html,
            """
            <select name="country" data-widget="filtered-select" data-filter-field="id_continent">
                <option value="">----</option>
                <option value="FR" data-filter-value="EU">France</option>
                <option value="JP" selected data-filter-value="AS">Japan</option>
                <option value="RU" data-filter-value="AS,EU">Russia</option>
            </select>
        """,
        )