(config, domain, new_mobile_ucr_restore)
return Detail(
        id='reports.{}.data'.format(config.uuid),
        nodeset=(
            nodeset_string.format(
                MobileSelectFilterHelpers.get_data_filter_xpath(config, domain, new_mobile_ucr_restore))
        ),
        title=Text(
            locale=Locale(id=id_strings.report_data_table()),
        ),
        fields=fields + [
            _column_to_field(c) for c in config.report(domain).report_columns
            if c.type != 'expanded' and c.visible
        ]
    )
Adds a data table to the report
Adds a data table to the report
Adds a data table to the report
def _get_data_detail(config, domain, new_mobile_ucr_restore):
    """
    Adds a data table to the report
    """
    def get_xpath(column_id):
        if new_mobile_ucr_restore:
            return TextXPath(
                function="{}".format(column_id),
            )
        else:
            return TextXPath(
                function="column[@id='{}']".format(column_id),
            )
    def _column_to_field(column):
        def _get_xpath(col):
            def _get_conditional(condition, if_true, if_false):
                return 'if({condition}, {if_true}, {if_false})'.format(
                    condition=condition,
                    if_true=if_true,
                    if_false=if_false,
                )

            def _get_word_eval(word_translations, default_value):
                word_eval = default_value
                for lang, translation in word_translations.items():
                    word_eval = _get_conditional(
                        "$lang = '{lang}'".format(
                            lang=lang,
                        ),
                        "'{translation}'".format(
                            translation=translation.replace("'", "''"),
                        ),
                        word_eval
                    )
                return word_eval

            try:
                transform = col['transform']
            except KeyError:
                transform = {}

            if transform.get('type') == 'translation':
                if new_mobile_ucr_restore:
                    default_val = "{column_id}"
                else:
                    default_val = "column[@id='{column_id}']"
                xpath_function = default_val
                for word, translations in transform['translations'].items():
                    if isinstance(translations, str):
                        # This is a flat mapping, not per-language translations
                        word_eval = "'{}'".format(translations)
                    else:
                        word_eval = _get_word_eval(translations, default_val)
                    xpath_function = _get_conditional(
                        "{value} = '{word}'".format(
                            value=default_val,
                            word=word,
                        ),
                        word_eval,
                        xpath_function
                    )
                return TextXPath(
                    function=xpath_function.format(
                        column_id=col.column_id
                    ),
                    variables=[XPathVariable(name='lang', locale_id='lang.current')],
                )
            else:
                return get_xpath(col.column_id)

        return Field(
            header=Header(
                text=Text(
                    locale=Locale(
                        id=id_strings.report_column_header(config.uuid, column.column_id)
                    ),
                )
            ),
            template=Template(
                text=Text(
                    xpath=_get_xpath(column),
                )
            ),
        )

    nodeset_string = 'row{}' if new_mobile_ucr_restore else 'rows/row{}'
    if toggles.ADD_ROW_INDEX_TO_MOBILE_UCRS.enabled(domain):
        fields = [Field(
            header=Header(text=Text(), width=0,),
            template=Template(text=Text(), width=0,),
            sort_node=Sort(type='int', direction='ascending', order='1',
                           text=Text(xpath=get_xpath("row_index")),)
        )]
    else:
        fields = []
    return Detail(
        id='reports.{}.data'.format(config.uuid),
        nodeset=(
            nodeset_string.format(
                MobileSelectFilterHelpers.get_data_filter_xpath(config, domain, new_mobile_ucr_restore))
        ),
        title=Text(
            locale=Locale(id=id_strings.report_data_table()),
        ),
        fields=fields + [
            _column_to_field(c) for c in config.report(domain).report_columns
            if c.type != 'expanded' and c.visible
        ]
    )
def _get_data_detail ( config , domain , new_mobile_ucr_restore ) : def get_xpath ( column_id ) : if new_mobile_ucr_restore : return TextXPath ( function = "{}" . format ( column_id ) , ) else : return TextXPath ( function = "column[@id='{}']" . format ( column_id ) , ) def _column_to_field ( column ) : def _get_xpath ( col ) : def _get_conditional ( condition , if_true , if_false ) : return 'if({condition}, {if_true}, {if_false})' . format ( condition = condition , if_true = if_true , if_false = if_false , ) def _get_word_eval ( word_translations , default_value ) : word_eval = default_value for lang , translation in word_translations . items ( ) : word_eval = _get_conditional ( "$lang = '{lang}'" . format ( lang = lang , ) , "'{translation}'" . format ( translation = translation . replace ( "'" , "''" ) , ) , word_eval ) return word_eval try : transform = col [ 'transform' ] except KeyError : transform = { } if transform . get ( 'type' ) == 'translation' : if new_mobile_ucr_restore : default_val = "{column_id}" else : default_val = "column[@id='{column_id}']" xpath_function = default_val for word , translations in transform [ 'translations' ] . items ( ) : if isinstance ( translations , str ) : # This is a flat mapping, not per-language translations word_eval = "'{}'" . format ( translations ) else : word_eval = _get_word_eval ( translations , default_val ) xpath_function = _get_conditional ( "{value} = '{word}'" . format ( value = default_val , word = word , ) , word_eval , xpath_function ) return TextXPath ( function = xpath_function . format ( column_id = col . column_id ) , variables = [ XPathVariable ( name = 'lang' , locale_id = 'lang.current' ) ] , ) else : return get_xpath ( col . column_id ) return Field ( header = Header ( text = Text ( locale = Locale ( id = id_strings . report_column_header ( config . uuid , column . column_id ) ) , ) ) , template = Template ( text = Text ( xpath = _get_xpath ( column ) , ) ) , ) nodeset_string = 'row{}' if new_mobile_ucr_restore else 'rows/row{}' if toggles . ADD_ROW_INDEX_TO_MOBILE_UCRS . enabled ( domain ) : fields = [ Field ( header = Header ( text = Text ( ) , width = 0 , ) , template = Template ( text = Text ( ) , width = 0 , ) , sort_node = Sort ( type = 'int' , direction = 'ascending' , order = '1' , text = Text ( xpath = get_xpath ( "row_index" ) ) , ) ) ] else : fields = [ ] return Detail ( id = 'reports.{}.data' . format ( config . uuid ) , nodeset = ( nodeset_string . format ( MobileSelectFilterHelpers . get_data_filter_xpath ( config , domain , new_mobile_ucr_restore ) ) ) , title = Text ( locale = Locale ( id = id_strings . report_data_table ( ) ) , ) , fields = fields + [ _column_to_field ( c ) for c in config . report ( domain ) . report_columns if c . type != 'expanded' and c . visible ] )