当前位置: 首页>>代码示例>>Python>>正文


Python AttributeInfo.gather_aliases方法代码示例

本文整理汇总了Python中ggrc.models.reflection.AttributeInfo.gather_aliases方法的典型用法代码示例。如果您正苦于以下问题:Python AttributeInfo.gather_aliases方法的具体用法?Python AttributeInfo.gather_aliases怎么用?Python AttributeInfo.gather_aliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ggrc.models.reflection.AttributeInfo的用法示例。


在下文中一共展示了AttributeInfo.gather_aliases方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_reserved_names

# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_aliases [as 别名]
  def _get_reserved_names(cls, definition_type):
    """Get a list of all attribute names in all objects.

    On first call this function computes all possible names that can be used by
    any model and stores them in a static frozen set. All later calls just get
    this set.

    Returns:
      frozen set containing all reserved attribute names for the current
      object.
    """
    # pylint: disable=protected-access
    # The _inflector is a false positive in our app.
    with benchmark("Generate a list of all reserved attribute names"):
      if not cls._reserved_names.get(definition_type):
        definition_map = {model._inflector.table_singular: model
                          for model in ggrc.models.all_models.all_models}
        definition_map.update({model._inflector.model_singular: model
                              for model in ggrc.models.all_models.all_models})

        definition_model = definition_map.get(definition_type)
        if not definition_model:
          raise ValueError("Invalid definition type")

        aliases = AttributeInfo.gather_aliases(definition_model)
        cls._reserved_names[definition_type] = frozenset(
            (value["display_name"] if isinstance(
                value, dict) else value).lower()
            for value in aliases.values() if value
        )
      return cls._reserved_names[definition_type]
开发者ID:Smotko,项目名称:ggrc-core,代码行数:33,代码来源:attributevalidator.py

示例2: _set_attr_name_map

# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_aliases [as 别名]
  def _set_attr_name_map(self):
    """ build a map for attributes names and display names

    Dict containing all display_name to attr_name mappings
    for all objects used in the current query
    Example:
        { Program: {"Program URL": "url", "Code": "slug", ...} ...}
    """
    self.attr_name_map = {}
    for object_query in self.query:
      object_name = object_query["object_name"]
      object_class = self.object_map[object_name]
      tgt_class = object_class
      if object_name == "Snapshot":
        child_type = self._get_snapshot_child_type(object_query)
        tgt_class = getattr(models.all_models, child_type, object_class)
      aliases = AttributeInfo.gather_aliases(tgt_class)
      self.attr_name_map[tgt_class] = {}
      for key, value in aliases.items():
        filter_by = None
        if isinstance(value, dict):
          filter_name = value.get("filter_by", None)
          if filter_name is not None:
            filter_by = getattr(tgt_class, filter_name, None)
          name = value["display_name"]
        else:
          name = value
        if name:
          self.attr_name_map[tgt_class][name.lower()] = (key.lower(),
                                                         filter_by)
开发者ID:VinnieJohns,项目名称:ggrc-core,代码行数:32,代码来源:query_helper.py

示例3: test_gather_aliases

# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_aliases [as 别名]
  def test_gather_aliases(self):
    """Test gather all aliases."""
    class Child(object):
      # pylint: disable=too-few-public-methods
      _aliases = {
          "child_normal": "normal",
          "child_extended": {
              "display_name": "Extended",
          },
          "child_filter_only": {
              "display_name": "Extended",
              "filter_only": True,
          },
      }

    class Parent(Child):
      # pylint: disable=too-few-public-methods
      _aliases = {
          "parent_normal": "normal",
          "parent_extended": {
              "display_name": "Extended",
          },
          "parent_filter_only": {
              "display_name": "Extended",
              "filter_only": True,
          },
      }

    self.assertEqual(
        AttributeInfo.gather_aliases(Parent),
        {
            "parent_normal": "normal",
            "parent_extended": {
                "display_name": "Extended",
            },
            "parent_filter_only": {
                "display_name": "Extended",
                "filter_only": True,
            },
            "child_normal": "normal",
            "child_extended": {
                "display_name": "Extended",
            },
            "child_filter_only": {
                "display_name": "Extended",
                "filter_only": True,
            },
        }
    )
开发者ID:egorhm,项目名称:ggrc-core,代码行数:51,代码来源:test_reflection.py

示例4: _get_model_names

# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_aliases [as 别名]
  def _get_model_names(cls, model):
    """Get tuple of all attribute names for model.

    Args:
        model: Model class.

    Returns:
        Tuple of all attributes for provided model.
    """
    if not model:
      raise ValueError("Invalid definition type")
    aliases = AttributeInfo.gather_aliases(model)
    return (
        (value["display_name"] if isinstance(value, dict) else value).lower()
        for value in aliases.values() if value
    )
开发者ID:egorhm,项目名称:ggrc-core,代码行数:18,代码来源:attributevalidator.py

示例5: attributes_map

# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_aliases [as 别名]
 def attributes_map(cls):
   if cls.CACHED_ATTRIBUTE_MAP:
     return cls.CACHED_ATTRIBUTE_MAP
   aliases = AttributeInfo.gather_aliases(cls)
   cls.CACHED_ATTRIBUTE_MAP = {}
   for key, value in aliases.items():
     if isinstance(value, dict):
       name = value["display_name"]
       filter_by = None
       if value.get("filter_by"):
         filter_by = getattr(cls, value["filter_by"], None)
     else:
       name = value
       filter_by = None
     if not name:
       continue
     tmp = getattr(cls, "PROPERTY_TEMPLATE", "{}")
     name = tmp.format(name)
     key = tmp.format(key)
     cls.CACHED_ATTRIBUTE_MAP[name.lower()] = (key.lower(), filter_by)
   return cls.CACHED_ATTRIBUTE_MAP
开发者ID:zidarsk8,项目名称:ggrc-core,代码行数:23,代码来源:__init__.py


注:本文中的ggrc.models.reflection.AttributeInfo.gather_aliases方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。