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


Python ShotgunORM.onEntityCreate方法代码示例

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


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

示例1: _createEntity

# 需要导入模块: import ShotgunORM [as 别名]
# 或者: from ShotgunORM import onEntityCreate [as 别名]
  def _createEntity(self, sgEntityType, sgData, sgSyncFields=None):
    '''
    Internal function!

    Locks the connection and if the Entity has an ID the cache is checked to see
    if it already has an SgEntity and if so it returns it otherwise it creates one.
    '''

    ShotgunORM.LoggerConnection.debug('%(connection)s._createEntity(...)', {'connection': self})
    ShotgunORM.LoggerConnection.debug('    * sgEntityType: %(entityName)s', {'entityName': sgEntityType})
    ShotgunORM.LoggerConnection.debug('    * sgData: %(sgData)s', {'sgData': sgData})

    with self:
      sgData = dict(sgData)

      factory = self.classFactory()

      result = None

      eId = None

      if sgData.has_key('id'):
        eId = int(sgData['id'])
      else:
        eId = -1

      if not self.__entityCache.has_key(sgEntityType):
        self.__entityCache[sgEntityType] = {}

      # Return immediately if the Entity does not exist.
      if eId <= -1:
        sgData['id'] = -id(result)

        result = factory.createEntity(self, sgEntityType, sgData)

        ShotgunORM.onEntityCreate(result)

        return result

      onCreate = False

      # Check the cache and if its found update any non-valid fields that
      # have data contained in the passed sgData.  If not found create the
      # Entity and add it to the cache.]
      if self.__entityCache[sgEntityType].has_key(eId):
        result = self.__entityCache[sgEntityType][eId]['entity']

        if result != None:
          result = result()

        if result == None:
          cacheData = self.__entityCache[sgEntityType][eId]['cache']

          tmpData = {
            'id': eId,
            'type': sgEntityType
          }

          tmpData.update(cacheData)

          result = factory.createEntity(self, sgEntityType, tmpData)

          self.__entityCache[sgEntityType][eId]['entity'] = weakref.ref(result)

          onCreate = True

        with result:
          del sgData['id']
          del sgData['type']

          for field, value in sgData.items():
            fieldObj = result.field(field)

            if fieldObj.isValid() or fieldObj.hasCommit() or fieldObj.hasSyncUpdate():
              continue

            fieldObj.invalidate()

            fieldObj._updateValue = value

            fieldObj.setHasSyncUpdate(True)
      else:
        result = factory.createEntity(self, sgEntityType, sgData)

        self.__entityCache[sgEntityType][eId] = {
          'entity': weakref.ref(result),
          'cache': {}
        }

        onCreate = True

      if sgSyncFields != None:
        result.sync(sgSyncFields, ignoreValid=True, ignoreWithUpdate=True, backgroundPull=True)

      if onCreate:
        ShotgunORM.onEntityCreate(result)

      return result
开发者ID:AndrejAleksic,项目名称:python-shotgunorm,代码行数:100,代码来源:SgConnection.py


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