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


Python AttributeInfo.gather_update_raw方法代码示例

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


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

示例1: do_update_attr

# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_update_raw [as 别名]
  def do_update_attr(cls, obj, json_obj, attr):
    """Perform the update to ``obj`` required to make the attribute attr
    equivalent in ``obj`` and ``json_obj``.
    """
    class_attr = getattr(obj.__class__, attr)
    attr_reflection = AttributeInfo.get_attr(obj.__class__, "_api_attrs", attr)
    update_raw = attr in AttributeInfo.gather_update_raw(obj.__class__)
    if update_raw:
      # The attribute has a special setter that can handle raw json fields
      # properly. This is used for special mappings such as custom attribute
      # values
      attr_name = attr
      value = json_obj.get(attr_name)
    elif isinstance(attr_reflection, SerializableAttribute):
      attr_name = attr
      value = json_obj.get(attr)

      if value:
        value = attr_reflection.deserialize(value)
    elif hasattr(attr, '__call__'):
      # The attribute has been decorated with a callable, grab the name and
      # invoke the callable to get the value
      attr_name = attr.attr_name
      value = attr(cls, obj, json_obj)
    elif not hasattr(cls, class_attr.__class__.__name__):
      # The attribute is a function on the obj like custom_attributes in
      # CustomAttributable mixin
      attr_name = attr
      value = class_attr(obj, json_obj)
    else:
      # Lookup the method to use to perform the update. Use reflection to
      # key off of the type of the attribute and invoke the method of the
      # same name.
      attr_name = attr
      method = getattr(cls, class_attr.__class__.__name__)
      value = method(obj, json_obj, attr_name, class_attr)
    if (isinstance(value, (set, list)) and
        not update_raw and (
        not hasattr(class_attr, 'property') or not
        hasattr(class_attr.property, 'columns') or not isinstance(
            class_attr.property.columns[0].type,
            JsonType)
    )):
      cls._do_update_collection(obj, value, attr_name)
    else:
      try:
        setattr(obj, attr_name, value)
      except AttributeError as error:
        logger.error('Unable to set attribute %s: %s', attr_name, error)
        raise
开发者ID:google,项目名称:ggrc-core,代码行数:52,代码来源:json.py


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