Show More
@@ -0,0 +1,49 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | # Copyright (C) 2016-2017 RhodeCode GmbH | |||
|
4 | # | |||
|
5 | # This program is free software: you can redistribute it and/or modify | |||
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |||
|
7 | # (only), as published by the Free Software Foundation. | |||
|
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 General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU Affero General Public License | |||
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
|
16 | # | |||
|
17 | # This program is dual-licensed. If you wish to learn more about the | |||
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |||
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |||
|
20 | ||||
|
21 | import deform.widget | |||
|
22 | ||||
|
23 | ||||
|
24 | def convert_to_optgroup(items): | |||
|
25 | """ | |||
|
26 | Convert such format:: | |||
|
27 | ||||
|
28 | [ | |||
|
29 | ['rev:tip', u'latest tip'], | |||
|
30 | ([(u'branch:default', u'default')], u'Branches'), | |||
|
31 | ] | |||
|
32 | ||||
|
33 | into one used by deform Select widget:: | |||
|
34 | ||||
|
35 | ( | |||
|
36 | ('rev:tip', 'latest tip'), | |||
|
37 | OptGroup('Branches', | |||
|
38 | ('branch:default', 'default'), | |||
|
39 | ) | |||
|
40 | """ | |||
|
41 | result = [] | |||
|
42 | for value, label in items: | |||
|
43 | # option group | |||
|
44 | if isinstance(value, (tuple, list)): | |||
|
45 | result.append(deform.widget.OptGroup(label, *value)) | |||
|
46 | else: | |||
|
47 | result.append((value, label)) | |||
|
48 | ||||
|
49 | return result |
General Comments 0
You need to be logged in to leave comments.
Login now