def update_ancestors_dict(options, leaf_values_dict, parents): for option in options: children = option.get('options', []) if not children: if parents: if parents not in leaf_values_dict: leaf_values_dict[parents] = list() # list of child-values preserves order from the source yaml, for the benefit of # git history in output file leaf_values_dict[parents].append(utils.get_option_value(option)) else: update_ancestors_dict(children, leaf_values_dict, parents.union([utils.get_option_value(option)]))
def test_get_option_value(): option_value_no_label = { 'value': 'somevalue', } option_label_no_value = { 'label': 'somelabel', } option_label_and_value = { 'value': 'somevalue', 'label': 'somelabel', } assert get_option_value(option_value_no_label) == 'somevalue' assert get_option_value(option_label_no_value) == 'somelabel' assert get_option_value(option_label_and_value) == 'somevalue'
def _derived_options_transformation_generator(checkbox_question): retval = [{ 'append_conditionally': OrderedDict(( ('field', option['derived_from']['question']), ('target_field', checkbox_question.id), ('any_of', option['derived_from']['any_of']), ('append_value', [utils.get_option_value(option)]), )) } for option in checkbox_question.get('options') if option.get('derived_from', None) is not None] return retval
def _derived_options_transformation_generator(checkbox_question): retval = [ { 'append_conditionally': OrderedDict(( ('field', option['derived_from']['question']), ('target_field', checkbox_question.id), ('any_of', option['derived_from']['any_of']), ('append_value', [utils.get_option_value(option)]), )) } for option in checkbox_question.get('options') if option.get('derived_from', None) is not None ] return retval