def to_hash(self, recursion_depth=1): """Convert the object to a hash.""" obj = super(InstitutionPerson, self).to_hash(recursion_depth) obj['_id'] = index_hash(int(self.person.id), int(self.institution.id)) obj['person_id'] = int(self.person.id) obj['institution_id'] = int(self.institution.id) return obj
def test_index_hash(self): """ Test the index hash method with some static knowns """ in_data = (123, 456) chk_data = "e10adc3949ba59abbe56e057f20f883e" self.assertEqual(index_hash(*in_data), chk_data)
def to_hash(self): """Convert the object to a hash.""" obj = super(CitationProposal, self).to_hash() obj['_id'] = index_hash(int(self.citation.id), unicode_type(self.proposal.id)) obj['citation_id'] = int(self.citation.id) obj['proposal_id'] = unicode_type(self.proposal.id) return obj
def available_hash_list(cls): """ Need to figure out more about what this does... """ keys = cls.get_primary_keys() # pylint: disable=no-member table = cls._meta.db_table # pylint: enable=no-member db_keys = {} for key in keys: # pylint: disable=no-member if len(cls._meta.rel) > 0: rel_mod = cls._meta.rel.get(key) db_keys[key] = rel_mod.db_column else: db_keys[key] = key # pylint: enable=no-member hash_list = [] hash_dict = {} sql = "SELECT {0} FROM {1}".format(",".join(db_keys.values()), table) all_keys_query = RawQuery(cls, sql, None).dicts() for obj in all_keys_query.execute(): inst_key = index_hash(*obj.values()) hash_list.append(inst_key) entry = { 'key_list': {db_keys.get(key): obj[key] for key in db_keys.keys()}, 'index_hash': inst_key } hash_dict[inst_key] = entry return hash_list, hash_dict
def to_hash(self): """Convert the object to a hash.""" obj = super(InstrumentGroup, self).to_hash() obj['_id'] = index_hash(int(self.group.id), int(self.instrument.id)) obj['instrument_id'] = int(self.instrument.id) obj['group_id'] = int(self.group.id) return obj
def to_hash(self, recursion_depth=1): """Convert the object to a hash.""" obj = super(UserGroup, self).to_hash(recursion_depth) obj['_id'] = index_hash(int(self.person.id), int(self.group.id)) obj['person_id'] = int(self.person.id) obj['group_id'] = int(self.group.id) return obj
def to_hash(self, recursion_depth=1): """Convert the object to a hash.""" obj = super(InstrumentCustodian, self).to_hash(recursion_depth) obj['_id'] = index_hash(int(self.custodian.id), int(self.instrument.id)) obj['instrument_id'] = int(self.instrument.id) obj['custodian_id'] = int(self.custodian.id) return obj
def to_hash(self, recursion_depth=1): """Convert the object to a hash.""" obj = super(ProposalParticipant, self).to_hash(recursion_depth) obj['_id'] = index_hash(unicode_type(self.proposal.id), int(self.person.id)) obj['person_id'] = int(self.person.id) obj['proposal_id'] = unicode_type(self.proposal.id) return obj
def to_hash(self): """Convert the object to a hash.""" obj = super(ProposalInstrument, self).to_hash() obj['_id'] = index_hash(unicode_type(self.proposal.id), int(self.instrument.id)) obj['instrument_id'] = int(self.instrument.id) obj['proposal_id'] = unicode_type(self.proposal.id) return obj
def to_hash(self): """Convert the object to a hash.""" obj = super(AToolProposal, self).to_hash() obj['_id'] = index_hash(unicode_type(self.proposal.id), int(self.analytical_tool.id)) obj['proposal_id'] = unicode_type(self.proposal.id) obj['analytical_tool_id'] = int(self.analytical_tool.id) return obj
def to_hash(self, recursion_depth=1): """Convert the object to a hash.""" obj = super(CitationContributor, self).to_hash(recursion_depth) obj['_id'] = index_hash(int(self.citation.id), int(self.author.id)) obj['citation_id'] = int(self.citation.id) obj['author_id'] = int(self.author.id) obj['author_precedence'] = int(self.author_precedence) return obj
def to_hash(self, recursion_depth=1): """Convert the object to a hash.""" obj = super(AToolTransaction, self).to_hash(recursion_depth) obj['_id'] = index_hash(int(self.transaction.id), int(self.analytical_tool.id)) obj['transaction_id'] = int(self.transaction.id) obj['analytical_tool_id'] = int(self.analytical_tool.id) return obj
def to_hash(self): """ Converts the object to a hash """ obj = super(InstrumentGroup, self).to_hash() obj['_id'] = index_hash(int(self.group.id), int(self.instrument.id)) obj['instrument_id'] = int(self.instrument.id) obj['group_id'] = int(self.group.id) return obj
def to_hash(self): """ Converts the object to a hash """ obj = super(ProposalInstrument, self).to_hash() obj['_id'] = index_hash(str(self.proposal.id), int(self.instrument.id)) obj['instrument_id'] = int(self.instrument.id) obj['proposal_id'] = str(self.proposal.id) return obj
def to_hash(self): """Convert the base object fields into serializable attributes in a hash.""" obj = {} obj['created'] = self.created.isoformat() obj['updated'] = self.updated.isoformat() obj['deleted'] = self.deleted.isoformat( ) if self.deleted is not None else None obj['_id'] = index_hash(obj['created'], obj['updated'], obj['deleted']) return obj
def to_hash(self): """ Converts the object to a hash """ obj = super(InstitutionPerson, self).to_hash() obj['_id'] = index_hash(int(self.person.id), int(self.institution.id)) obj['person_id'] = int(self.person.id) obj['institution_id'] = int(self.institution.id) return obj
def to_hash(self, recursion_depth=1): """Convert the object to a hash.""" obj = super(TransactionKeyValue, self).to_hash(recursion_depth) obj['_id'] = index_hash(int(self.key.id), int(self.transaction.id), int(self.value.id)) obj['transaction_id'] = int(self.transaction.id) obj['key_id'] = int(self.key.id) obj['value_id'] = int(self.value.id) return obj
def to_hash(self): """Convert the object to a hash.""" obj = super(FileKeyValue, self).to_hash() obj['_id'] = index_hash(int(self.key.id), int(self.file.id), int(self.value.id)) obj['file_id'] = int(self.file.id) obj['key_id'] = int(self.key.id) obj['value_id'] = int(self.value.id) return obj
def to_hash(self): """Convert the object to a hash.""" obj = super(CitationKeyword, self).to_hash() # pylint: disable=no-member obj['_id'] = index_hash(int(self.citation.id), int(self.keyword.id)) obj['citation_id'] = int(self.citation.id) obj['keyword_id'] = int(self.keyword.id) # pylint: enable=no-member return obj
def to_hash(self): """ Converts the object to a hash """ obj = super(InstrumentCustodian, self).to_hash() obj['_id'] = index_hash(int(self.custodian.id), int(self.instrument.id)) obj['instrument_id'] = int(self.instrument.id) obj['person_id'] = int(self.custodian.id) return obj
def to_hash(self): """ Converts the object to a hash """ obj = super(CitationProposal, self).to_hash() obj['_id'] = index_hash(int(self.citation.id), str(self.proposal.id)) obj['citation_id'] = int(self.citation.id) obj['proposal_id'] = str(self.proposal.id) return obj
def to_hash(self): """ Converts the object to a hash """ obj = super(ProposalParticipant, self).to_hash() obj['_id'] = index_hash(str(self.proposal.id), int(self.person.id)) obj['person_id'] = int(self.person.id) obj['proposal_id'] = str(self.proposal.id) return obj
def to_hash(self): """ Converts the object to a hash """ obj = super(CitationContributor, self).to_hash() obj['_id'] = index_hash(int(self.citation.id), int(self.author.id)) obj['citation_id'] = int(self.citation.id) obj['author_id'] = int(self.author.id) obj['author_precedence'] = int(self.author_precedence) return obj
def to_hash(self, recursion_depth=0): """Convert the base object fields into serializable attributes in a hash.""" obj = {} obj['created'] = self.created.isoformat() obj['updated'] = self.updated.isoformat() obj['deleted'] = self.deleted.isoformat() if self.deleted is not None else None obj['_id'] = index_hash(obj['created'], obj['updated'], obj['deleted']) if recursion_depth: for attr in self.cls_revforeignkeys(): obj[attr] = [obj_ref.to_hash(recursion_depth - 1) for obj_ref in getattr(self, attr)] return obj
def to_hash(self): """ Converts the base object fields into serializable attributes in a hash. """ obj = {} obj['created'] = self.created.isoformat() obj['updated'] = self.updated.isoformat() obj['deleted'] = self.deleted.isoformat() if self.deleted is not None else None obj['_id'] = index_hash(obj['created'], obj['updated'], obj['deleted']) return obj
def to_hash(self): """ Converts the object to a hash """ obj = super(TransactionKeyValue, self).to_hash() obj['_id'] = index_hash(int(self.key.id), int(self.transaction.id), int(self.value.id)) obj['transaction_id'] = int(self.transaction.id) obj['key_id'] = int(self.key.id) obj['value_id'] = int(self.value.id) return obj
def to_hash(self): """ Converts the object to a hash """ obj = super(FileKeyValue, self).to_hash() obj['_id'] = index_hash(int(self.key.id), int(self.file.id), int(self.value.id)) obj['file_id'] = int(self.file.id) obj['key_id'] = int(self.key.id) obj['value_id'] = int(self.value.id) return obj
def available_hash_list(cls): """ Generate a hashable structure of all keys and values of keys. This structure allows for easy evaluation of updates or current vs old data for any object in the database. """ hash_list = [] hash_dict = {} all_keys_query = cls.select( *[getattr(cls, key) for key in cls.get_primary_keys()]).dicts() for obj in all_keys_query.execute(): inst_key = index_hash(*obj.values()) hash_list.append(inst_key) entry = {'key_list': obj, 'index_hash': inst_key} hash_dict[inst_key] = entry return hash_list, hash_dict
def test_index_hash(self): """Test the index hash method with some static knowns.""" in_data = (123, 456) chk_data = 'e10adc3949ba59abbe56e057f20f883e' self.assertEqual(index_hash(*in_data), chk_data)