當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。