def _get_report_context_tile_detail(): from corehq.apps.app_manager.suite_xml.features.mobile_ucr import MOBILE_UCR_TILE_DETAIL_ID return Detail( id=MOBILE_UCR_TILE_DETAIL_ID, title=Text(), fields=[ Field( style=Style( horz_align="left", font_size="small", grid_height=1, grid_width=12, grid_x=0, grid_y=0, ), header=Header(text=Text()), template=Template(text=Text(xpath=Xpath( function= "concat($message, ' ', format-date(date(instance('commcare-reports:index')/report_index/reports/@last_update), '%e/%n/%Y'))", variables=[ XpathVariable( name='message', locale_id=id_strings.reports_last_updated_on()) ], ))), ) ])
def _get_enum_variables(self, column): variables = [] for i, mapping in enumerate(column.enum): variables.append( XpathVariable(name=mapping.key_as_variable, locale_id=id_strings.detail_column_enum_variable( self.module, self.detail_type, column, mapping.key_as_variable)).serialize()) return ''.join(variables)
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, six.string_types): soft_assert_type_text(translations) # 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 Xpath( function=xpath_function.format(column_id=col.column_id), variables=[ XpathVariable(name='lang', locale_id='lang.current') ], ) else: if new_mobile_ucr_restore: return Xpath(function="{}".format(col.column_id), ) else: return Xpath(function="column[@id='{}']".format( col.column_id), )
def _get_xpath(col): def _get_conditional(condition, if_true, if_false): return u'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, ), u"'{translation}'".format( translation=translation.replace("'", "''"), ), word_eval) return word_eval transform = col['transform'] if transform.get('type') == 'translation': default_val = "column[@id='{column_id}']" xpath_function = default_val for word, translations in transform['translations'].items(): if isinstance(translations, basestring): # 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( u"{value} = '{word}'".format( value=default_val, word=word, ), word_eval, xpath_function) return Xpath( function=xpath_function.format(column_id=col.column_id), variables=[ XpathVariable(name='lang', locale_id='lang.current') ], ) else: return Xpath(function="column[@id='{}']".format( col.column_id), )