Esempio n. 1
0
def parse_request_export_options(params):  # pylint: disable=too-many-branches
    """
    Parse export options in the request object into values returned in a
    list. The list represents a boolean for whether the group name should be
    removed, the group delimiter, and a boolean for whether select multiples
    should be split.
    """
    boolean_list = ['true', 'false']
    options = {}
    remove_group_name = params.get('remove_group_name') and \
        params.get('remove_group_name').lower()
    binary_select_multiples = params.get('binary_select_multiples')
    do_not_split_select_multiples = params.get('do_not_split_select_multiples')
    include_labels = params.get('include_labels', False)
    include_labels_only = params.get('include_labels_only', False)
    include_hxl = params.get('include_hxl', True)
    value_select_multiples = params.get('value_select_multiples')

    if include_labels is not None:
        options['include_labels'] = str_to_bool(include_labels)

    if include_labels_only is not None:
        options['include_labels_only'] = str_to_bool(include_labels_only)

    if include_hxl is not None:
        options['include_hxl'] = str_to_bool(include_hxl)

    if remove_group_name in boolean_list:
        options["remove_group_name"] = str_to_bool(remove_group_name)
    else:
        options["remove_group_name"] = False

    if params.get("group_delimiter") in ['.', DEFAULT_GROUP_DELIMITER]:
        options['group_delimiter'] = params.get("group_delimiter")
    else:
        options['group_delimiter'] = DEFAULT_GROUP_DELIMITER

    options['split_select_multiples'] = \
        not str_to_bool(do_not_split_select_multiples)
    if binary_select_multiples:
        options['binary_select_multiples'] = str_to_bool(
            binary_select_multiples)

    if 'include_images' in params:
        options["include_images"] = str_to_bool(params.get("include_images"))
    else:
        options["include_images"] = settings.EXPORT_WITH_IMAGE_DEFAULT

    options['win_excel_utf8'] = str_to_bool(params.get('win_excel_utf8'))

    if value_select_multiples and value_select_multiples in boolean_list:
        options['value_select_multiples'] = str_to_bool(value_select_multiples)

    index_tags = get_repeat_index_tags(params.get("repeat_index_tags"))
    if index_tags:
        options['repeat_index_tags'] = index_tags

    return options
Esempio n. 2
0
def parse_request_export_options(params):  # pylint: disable=too-many-branches
    """
    Parse export options in the request object into values returned in a
    list. The list represents a boolean for whether the group name should be
    removed, the group delimiter, and a boolean for whether select multiples
    should be split.
    """
    boolean_list = ['true', 'false']
    options = {}
    remove_group_name = params.get('remove_group_name') and \
        params.get('remove_group_name').lower()
    binary_select_multiples = params.get('binary_select_multiples') and \
        params.get('binary_select_multiples').lower()
    do_not_split_select_multiples = params.get(
        'do_not_split_select_multiples')
    include_labels = params.get('include_labels', False)
    include_reviews = params.get('include_reviews', False)
    include_labels_only = params.get('include_labels_only', False)
    include_hxl = params.get('include_hxl', True)
    value_select_multiples = params.get('value_select_multiples') and \
        params.get('value_select_multiples').lower()
    show_choice_labels = params.get('show_choice_labels') and \
        params.get('show_choice_labels').lower()

    if include_labels is not None:
        options['include_labels'] = str_to_bool(include_labels)

    if include_reviews is not None:
        options['include_reviews'] = str_to_bool(include_reviews)

    if include_labels_only is not None:
        options['include_labels_only'] = str_to_bool(include_labels_only)

    if include_hxl is not None:
        options['include_hxl'] = str_to_bool(include_hxl)

    if remove_group_name in boolean_list:
        options["remove_group_name"] = str_to_bool(remove_group_name)
    else:
        options["remove_group_name"] = False

    if params.get("group_delimiter") in ['.', DEFAULT_GROUP_DELIMITER]:
        options['group_delimiter'] = params.get("group_delimiter")
    else:
        options['group_delimiter'] = DEFAULT_GROUP_DELIMITER

    options['split_select_multiples'] = \
        not str_to_bool(do_not_split_select_multiples)
    if binary_select_multiples and binary_select_multiples in boolean_list:
        options['binary_select_multiples'] = str_to_bool(
            binary_select_multiples)

    if 'include_images' in params:
        options["include_images"] = str_to_bool(
            params.get("include_images"))
    else:
        options["include_images"] = settings.EXPORT_WITH_IMAGE_DEFAULT

    options['win_excel_utf8'] = str_to_bool(params.get('win_excel_utf8'))

    if value_select_multiples and value_select_multiples in boolean_list:
        options['value_select_multiples'] = str_to_bool(value_select_multiples)

    if show_choice_labels and show_choice_labels in boolean_list:
        options['show_choice_labels'] = str_to_bool(show_choice_labels)

    index_tags = get_repeat_index_tags(params.get("repeat_index_tags"))
    if index_tags:
        options['repeat_index_tags'] = index_tags

    if 'language' in params:
        options['language'] = params.get('language')

    return options