def _initialize_attributes(cls): """ Initialize attributes on the class. """ cls._attributes = {} cls._dynamo_to_python_attrs = {} for name, attribute in getmembers_issubclass(cls, Attribute): initialized = False if isinstance(attribute, MapAttribute): # MapAttribute instances that are class attributes of an AttributeContainer class # should behave like an Attribute instance and not an AttributeContainer instance. initialized = attribute._make_attribute() cls._attributes[name] = attribute if attribute.attr_name is not None: cls._dynamo_to_python_attrs[attribute.attr_name] = name else: attribute.attr_name = name if initialized and isinstance(attribute, MapAttribute): # To support creating expressions from nested attributes, MapAttribute instances # store local copies of the attributes in cls._attributes with `attr_path` set. # Prepend the `attr_path` lists with the dynamo attribute name. attribute._update_attribute_paths(attribute.attr_name)
def _get_attributes(cls): """ Returns the list of attributes for this class """ if cls.Meta.attributes is None: cls.Meta.attributes = {} for name, attribute in getmembers_issubclass(cls, Attribute): cls.Meta.attributes[name] = attribute return cls.Meta.attributes
def _get_attributes(cls): """ Returns the list of attributes for this class """ if cls.Meta.attributes is None: cls.Meta.attributes = {} for name, attribute in getmembers_issubclass(cls, Attribute): cls.Meta.attributes[name] = attribute return cls.Meta.attributes
def _get_indexes(cls): """ Returns a list of the secondary indexes """ if cls._indexes is None: cls._indexes = { pythonic(GLOBAL_SECONDARY_INDEXES): [], pythonic(LOCAL_SECONDARY_INDEXES): [], pythonic(ATTR_DEFINITIONS): [] } cls._index_classes = {} for name, index in getmembers_issubclass(cls, Index): cls._index_classes[index.Meta.index_name] = index schema = index._get_schema() idx = { pythonic(INDEX_NAME): index.Meta.index_name, pythonic(KEY_SCHEMA): schema.get(pythonic(KEY_SCHEMA)), pythonic(PROJECTION): { PROJECTION_TYPE: index.Meta.projection.projection_type, }, } if issubclass(index.__class__, GlobalSecondaryIndex): idx[pythonic(PROVISIONED_THROUGHPUT)] = { READ_CAPACITY_UNITS: index.Meta.read_capacity_units, WRITE_CAPACITY_UNITS: index.Meta.write_capacity_units } cls._indexes[pythonic(ATTR_DEFINITIONS)].extend( schema.get(pythonic(ATTR_DEFINITIONS))) if index.Meta.projection.non_key_attributes: idx[pythonic( PROJECTION )][NON_KEY_ATTRIBUTES] = index.Meta.projection.non_key_attributes if issubclass(index.__class__, GlobalSecondaryIndex): cls._indexes[pythonic(GLOBAL_SECONDARY_INDEXES)].append( idx) else: cls._indexes[pythonic(LOCAL_SECONDARY_INDEXES)].append(idx) return cls._indexes