本文整理汇总了Python中corehq.apps.userreports.transforms.factory.TransformFactory.get_transform方法的典型用法代码示例。如果您正苦于以下问题:Python TransformFactory.get_transform方法的具体用法?Python TransformFactory.get_transform怎么用?Python TransformFactory.get_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.userreports.transforms.factory.TransformFactory
的用法示例。
在下文中一共展示了TransformFactory.get_transform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bad_option
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def test_bad_option(self):
with self.assertRaises(BadSpecError):
TransformFactory.get_transform(
{
"type": "translation",
"mobile_or_web": "neither!",
"translations": {"0": "zero", "1": {"en": "one", "es": "uno"}, "2": {"en": "two", "es": "dos"}},
}
)
示例2: get_format_fn
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def get_format_fn(self):
"""
A function that gets applied to the data just in time before the report is rendered.
"""
if self.transform:
return TransformFactory.get_transform(self.transform).get_transform_function()
return None
示例3: test_string_transform
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def test_string_transform(self):
transform = TransformFactory.get_transform({
"type": "custom",
"custom_type": "days_elapsed_from_date"
})
date = (datetime.utcnow() - timedelta(days=5)).strftime('%Y-%m-%d')
self.assertEqual(transform.transform(date), 5)
示例4: test_gregorian_to_ethiopian
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def test_gregorian_to_ethiopian(self, date_string, expected_result):
transform = TransformFactory.get_transform({
"type": "custom",
"custom_type": "gregorian_date_to_ethiopian_date",
}).get_transform_function()
self.assertEqual(expected_result, transform(date_string))
示例5: test_basic_translation
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def test_basic_translation(self):
transform = TransformFactory.get_transform({
"type": "translation",
"translations": {
"#0000FF": "Blue"
},
}).get_transform_function()
self.assertEqual(transform('#0000FF'), 'Blue')
self.assertEqual(transform('#123456'), '#123456')
示例6: test_spanish_language_translation
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def test_spanish_language_translation(self):
transform = TransformFactory.get_transform(
{
"type": "translation",
"translations": {"#0000FF": {"en": "Blue", "es": "Azul"}, "#800080": {"en": "Purple", "es": "Morado"}},
}
).get_transform_function()
self.assertEqual(transform("#0000FF"), "Azul")
self.assertEqual(transform("#800080"), "Morado")
self.assertEqual(transform("#123456"), "#123456")
示例7: parsed_expression
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def parsed_expression(self, context):
from corehq.apps.userreports.expressions.factory import ExpressionFactory
expression = ExpressionFactory.from_spec(self.expression, context)
datatype_transform = transform_from_datatype(self.datatype)
if self.transform:
generic_transform = TransformFactory.get_transform(self.transform).get_transform_function()
inner_getter = TransformedGetter(expression, generic_transform)
else:
inner_getter = expression
return TransformedGetter(inner_getter, datatype_transform)
示例8: test_dont_translate_for_mobile
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def test_dont_translate_for_mobile(self):
transform = TransformFactory.get_transform({
"type": "translation",
"mobile_or_web": "mobile",
"translations": {
"#0000FF": "Blue",
"#800080": [["en", "Purple"], ["es", "Morado"]], # legacy, mobile-only format
},
}).get_transform_function()
self.assertEqual(transform('#0000FF'), '#0000FF')
self.assertEqual(transform('#800080'), '#800080')
self.assertEqual(transform('#123456'), '#123456')
示例9: test_multi_translation
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def test_multi_translation(self):
transform = TransformFactory.get_transform({
"type": "multiple_value_string_translation",
"translations": {
"#0000FF": "Blue",
"#800080": "Purple"
},
"delimiter": " "
}).get_transform_function()
self.assertEqual(transform('#0000FF #800080'), 'Blue Purple')
self.assertEqual(transform('#800080 #123456'), 'Purple #123456')
self.assertEqual(transform('#123 #123456'), '#123 #123456')
self.assertEqual(transform("#0000FF"), "Blue")
示例10: testInvalidType
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def testInvalidType(self):
with self.assertRaises(BadSpecError):
TransformFactory.get_transform({"type": "not_a_transform_type", "custom_type": "user_display"})
示例11: get_format_fn
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def get_format_fn(self):
if self.transform:
return TransformFactory.get_transform(self.transform).get_transform_function()
return None
示例12: test_missing_translation
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def test_missing_translation(self):
transform = TransformFactory.get_transform({"type": "translation", "translations": {}}).get_transform_function()
self.assertEqual(transform("foo"), "foo")
示例13: test_datetime_transform
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def test_datetime_transform(self):
transform = TransformFactory.get_transform({"type": "custom", "custom_type": "days_elapsed_from_date"})
self.assertEqual(transform.transform(datetime.utcnow() - timedelta(days=5)), 5)
示例14: testValidCustom
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def testValidCustom(self):
transform = TransformFactory.get_transform({"type": "custom", "custom_type": "user_display"})
self.assertTrue(isinstance(transform, CustomTransform))
示例15: testInvalidCustomType
# 需要导入模块: from corehq.apps.userreports.transforms.factory import TransformFactory [as 别名]
# 或者: from corehq.apps.userreports.transforms.factory.TransformFactory import get_transform [as 别名]
def testInvalidCustomType(self):
with self.assertRaises(BadSpecError):
TransformFactory.get_transform({"type": "custom", "custom_type": "not_valid"})