def from_hash(self, obj): """Convert the hash into the object.""" super(FileKeyValue, self).from_hash(obj) self._set_only_if('file_id', obj, 'file', lambda: Files.get(Files.id == obj['file_id'])) self._set_only_if('key_id', obj, 'key', lambda: Keys.get(Keys.id == obj['key_id'])) self._set_only_if('value_id', obj, 'value', lambda: Values.get(Values.id == obj['value_id']))
def from_hash(self, obj): """Convert the hash into the object.""" super(TransactionKeyValue, self).from_hash(obj) self._set_only_if( 'transaction_id', obj, 'transaction', lambda: Transactions.get(Transactions.id == obj['transaction_id']) ) self._set_only_if( 'value_id', obj, 'value', lambda: Values.get( Values.id == obj['value_id']) ) self._set_only_if( 'key_id', obj, 'key', lambda: Keys.get(Keys.id == obj['key_id']) )
def generate_tkvs(json): """Extract TransactionKeyValues as a hash from the json hash.""" keys = [] values = [] tkvs = [] for key, value in pull_kv_by_attr(json): keys.append({'key': key}) values.append({'value': value}) # pylint: disable=protected-access Keys()._set_or_create(keys) Values()._set_or_create(values) # pylint: enable=protected-access for key, value in pull_kv_by_attr(json): # key_obj = Keys.get(key=key) # value_obj = Values.get(value=value) tkvs.append({ 'key': Keys.get(key=key).id, 'transaction': transaction_hash['_id'], 'value': Values.get(value=value).id }) return tkvs
def generate_fkvs(json): """Extract FileKeyValues as a hash from the json hash.""" file_keys = [] file_values = [] fkvs = [] for key, value, file_id in pull_fkv_by_attr(json): file_keys.append({'key': key}) file_values.append({'value': value}) # pylint: disable=protected-access Keys()._set_or_create(file_keys) Values()._set_or_create(file_values) # pylint: enable=protected-access for key, value, file_id in pull_fkv_by_attr(json): # key_obj = # value_obj = Values.get(value=value) fkvs.append({ 'key': Keys.get(key=key).id, 'value': Values.get(value=value).id, 'file': file_id }) return fkvs