本文整理汇总了Python中ggrc.models.reflection.AttributeInfo.gather_visible_aliases方法的典型用法代码示例。如果您正苦于以下问题:Python AttributeInfo.gather_visible_aliases方法的具体用法?Python AttributeInfo.gather_visible_aliases怎么用?Python AttributeInfo.gather_visible_aliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ggrc.models.reflection.AttributeInfo
的用法示例。
在下文中一共展示了AttributeInfo.gather_visible_aliases方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _attribute_name_map
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_visible_aliases [as 别名]
def _attribute_name_map(self):
"""Get property to name mapping for object attributes."""
model = getattr(models.all_models, self.child_type, None)
if not model:
logger.warning("Exporting invalid snapshot model: %s", self.child_type)
return {}
aliases = AttributeInfo.gather_visible_aliases(model)
aliases.update(AttributeInfo.get_acl_definitions(model))
aliases.update(self.CUSTOM_SNAPSHOT_ALIASES)
if self.MAPPINGS_KEY in self.fields:
aliases.update(self.SNAPSHOT_MAPPING_ALIASES)
name_map = {
key: value["display_name"] if isinstance(value, dict) else value
for key, value in aliases.iteritems()
}
orderd_keys = AttributeInfo.get_column_order(name_map.keys())
return OrderedDict((key, name_map[key]) for key in orderd_keys)
示例2: test_gather_visible_aliases
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_visible_aliases [as 别名]
def test_gather_visible_aliases(self):
"""Test gather visible aliases."""
class Child(object):
# pylint: disable=too-few-public-methods
_aliases = {
"visible_child_normal": "normal",
"visible_child_extended": {
"display_name": "Extended",
},
"child_filter_only": {
"display_name": "Extended",
"filter_only": True,
},
}
class Parent(Child):
# pylint: disable=too-few-public-methods
_aliases = {
"visible_parent_normal": "normal",
"visible_parent_extended": {
"display_name": "Extended",
},
"parent_filter_only": {
"display_name": "Extended",
"filter_only": True,
},
}
self.assertEqual(
AttributeInfo.gather_visible_aliases(Parent),
{
"visible_parent_normal": "normal",
"visible_parent_extended": {
"display_name": "Extended",
},
"visible_child_normal": "normal",
"visible_child_extended": {
"display_name": "Extended",
},
}
)