Add preselection of default value in select lists.
Add detection of boolean select choices (OpenMS) to handle flag parameters properly.
Clemens BlanK
7 years ago
1028 | 1028 | option_node = add_child_node(param_node, "option", OrderedDict([("value", str(choice))])) |
1029 | 1029 | option_node.text = str(choice) |
1030 | 1030 | |
1031 | # preselect the default value | |
1032 | if param.default == choice: | |
1033 | option_node.attrib["selected"] = "true" | |
1034 | ||
1031 | 1035 | elif type(param.restrictions) is _NumericRange: |
1032 | 1036 | if param.type is not int and param.type is not float: |
1033 | 1037 | raise InvalidModelException("Expected either 'int' or 'float' in the numeric range restriction for " |
1188 | 1192 | |
1189 | 1193 | # determines if the given choices are boolean (basically, if the possible values are yes/no, true/false) |
1190 | 1194 | def is_boolean_parameter(param): |
1191 | return param.type is bool | |
1195 | ## detect boolean selects of OpenMS | |
1196 | if is_selection_parameter(param): | |
1197 | if len(param.restrictions.choices) == 2: | |
1198 | if "false" in param.restrictions.choices and "true" in param.restrictions.choices: | |
1199 | return True | |
1200 | else: | |
1201 | return param.type is bool | |
1192 | 1202 | |
1193 | 1203 | |
1194 | 1204 | # determines if there are choices for the parameter |