Example #1
0
  def buildFields(self):
    '''
    Creates all the fields for the Entity.

    After _buildFields(...) has been called buildUserFiels() is called.

    Note:
      This is called by the class factory after the Entity has been created and
      will immediately return anytime afterwards.
    '''

    # Only build the fields once!
    if self.__hasBuiltFields:
      return

    entityFieldInfos = self.schemaInfo().fieldInfos()

    # Add the type field.
    self._fields['type'] = ShotgunORM.SgFieldType(self, entityFieldInfos['type'])
    self._fields['id'] = ShotgunORM.SgFieldID(self, entityFieldInfos['id'])

    # Dont pass the "id" field as its manually built as a user field.  Same
    # for the type field.
    del entityFieldInfos['id']
    del entityFieldInfos['type']

    fieldClasses = ShotgunORM.SgField.__fieldclasses__

    for fieldInfo in entityFieldInfos.values():
      fieldName = fieldInfo.name()

      fieldClass = fieldClasses.get(fieldInfo.returnType(), None)

      newField = fieldClass(None, sgFieldSchemaInfo=fieldInfo)

      newField._SgField__setParentEntity(self)

      if hasattr(self.__class__, fieldName):
        ShotgunORM.LoggerField.warn(
          'Entity type %(entity)s field name "%(name)s confilicts with class method of same name' % {
            'entity': self.schemaInfo().name(),
            'name': fieldName
          }
        )

      self._fields[fieldName] = newField

    self._buildFields()

    self.__hasBuiltFields = True