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


Python AttributeInfo.get_object_attr_definitions方法代码示例

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


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

示例1: get_object_column_definitions

# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import get_object_attr_definitions [as 别名]
def get_object_column_definitions(object_class, fields=None,
                                  include_hidden=False):
  """Attach additional info to attribute definitions.

  Fetches the attribute info (_aliases) for the given object class and adds
  additional data (handler class, validator function, default value) )needed
  for imports.

  Args:
    object_class (db.Model): Model for which we want to get column definitions
      for imports.
    include_hidden (bool): Flag which specifies if we should include column
      handlers for hidden attributes (they marked as 'hidden'
      in _aliases dict).

  Returns:
    dict: Updated attribute definitions dict with additional data.
  """
  attributes = AttributeInfo.get_object_attr_definitions(
      object_class,
      fields=fields,
      include_hidden=include_hidden
  )
  column_handlers = model_column_handlers(object_class)
  for key, attr in attributes.iteritems():
    handler_key = attr.get("handler_key", key)
    # check full handler keys
    handler = column_handlers.get(handler_key)
    if not handler:
      # check handler key prefixes
      handler = column_handlers.get(handler_key.split(":")[0])
    if not handler:
      # use default handler
      handler = handlers.ColumnHandler
    validator = None
    default = None
    if attr["type"] == AttributeInfo.Type.PROPERTY:
      validator = getattr(object_class, "validate_{}".format(key), None)
      default = getattr(object_class, "default_{}".format(key), None)

    attr["handler"] = attr.get("handler", handler)
    attr["validator"] = attr.get("validator", validator)
    attr["default"] = attr.get("default", default)
  return attributes
开发者ID:google,项目名称:ggrc-core,代码行数:46,代码来源:import_helper.py

示例2: _get_assignable_dict

# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import get_object_attr_definitions [as 别名]
def _get_assignable_dict(people, notif):
  """Get dict data for assignable object in notification.

  Args:
    people (List[Person]): List o people objects who should receive the
      notification.
    notif (Notification): Notification that should be sent.
  Returns:
    dict: dictionary containing notification data for all people in the given
      list.
  """
  obj = get_notification_object(notif)
  data = {}

  definitions = AttributeInfo.get_object_attr_definitions(obj.__class__)
  roles = _get_assignable_roles(obj)

  for person in people:
    # We should default to today() if no start date is found on the object.
    start_date = getattr(obj, "start_date", datetime.date.today())
    data[person.email] = {
        "user": get_person_dict(person),
        notif.notification_type.name: {
            obj.id: {
                "title": obj.title,
                "start_date_statement": utils.get_digest_date_statement(
                    start_date, "start", True),
                "url": get_object_url(obj),
                "notif_created_at": {
                    notif.id: as_user_time(notif.created_at)},
                "notif_updated_at": {
                    notif.id: as_user_time(notif.updated_at)},
                "updated_fields": _get_updated_fields(obj,
                                                      notif.created_at,
                                                      definitions,
                                                      roles)
                if notif.notification_type.name == "assessment_updated"
                else None,
            }
        }
    }
  return data
开发者ID:egorhm,项目名称:ggrc-core,代码行数:44,代码来源:data_handlers.py


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