def from_hash(self, obj): """Convert the hash to an object.""" super(Files, self).from_hash(obj) self._set_only_if('_id', obj, 'id', lambda: int(obj['_id'])) self._set_only_if('name', obj, 'name', lambda: unicode_type(obj['name'])) self._set_only_if('subdir', obj, 'subdir', lambda: unicode_type(obj['subdir'])) self._set_only_if('mimetype', obj, 'mimetype', lambda: str(obj['mimetype'])) self._set_datetime_part('ctime', obj) self._set_datetime_part('mtime', obj) self._set_only_if('hashtype', obj, 'hashtype', lambda: str(obj['hashtype'])) self._set_only_if('hashsum', obj, 'hashsum', lambda: str(obj['hashsum'])) self._set_only_if('size', obj, 'size', lambda: int(obj['size'])) self._set_only_if('encoding', obj, 'encoding', lambda: str(obj['encoding'])) self._set_date_part('suspense_date', obj) def trans_func(): """Return the transaction for the obj id.""" return Transactions.get(Transactions.id == obj['transaction_id']) self._set_only_if('transaction_id', obj, 'transaction', trans_func)
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(DOITransaction, self).to_hash(**flags) obj['_id'] = index_hash(unicode_type(self.__data__['doi']), int(self.__data__['transaction'])) obj['doi'] = unicode_type(self.__data__['doi']) obj['transaction'] = int(self.__data__['transaction']) return obj
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(CitationProposal, self).to_hash(**flags) obj['_id'] = index_hash(int(self.__data__['citation']), unicode_type(self.__data__['proposal'])) obj['citation_id'] = int(self.__data__['citation']) obj['proposal_id'] = unicode_type(self.__data__['proposal']) return obj
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(ProposalGroup, self).to_hash(**flags) obj['_id'] = index_hash(unicode_type(self.__data__['proposal']), int(self.__data__['group'])) obj['group_id'] = int(self.__data__['group']) obj['proposal_id'] = unicode_type(self.__data__['proposal']) return obj
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(AToolProposal, self).to_hash(**flags) obj['_id'] = index_hash(unicode_type(self.__data__['proposal']), int(self.__data__['analytical_tool'])) obj['proposal_id'] = unicode_type(self.__data__['proposal']) obj['analytical_tool_id'] = int(self.__data__['analytical_tool']) return obj
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(Instruments, self).to_hash(**flags) obj['_id'] = self.id obj['name'] = unicode_type(self.name) obj['display_name'] = unicode_type(self.display_name) obj['name_short'] = unicode_type(self.name_short) obj['active'] = bool(self.active) obj['encoding'] = str(self.encoding) return obj
def from_hash(self, obj): """Convert the hash into the object.""" super(Instruments, self).from_hash(obj) self._set_only_if('_id', obj, 'id', lambda: int(obj['_id'])) self._set_only_if('name', obj, 'name', lambda: unicode_type(obj['name'])) self._set_only_if('display_name', obj, 'display_name', lambda: unicode_type(obj['display_name'])) self._set_only_if('name_short', obj, 'name_short', lambda: unicode_type(obj['name_short'])) self._set_only_if('active', obj, 'active', lambda: self._bool_translate(obj['active'])) self._set_only_if('encoding', obj, 'encoding', lambda: str(obj['encoding']))
def to_hash(self, **flags): """Convert the object fields into a serializable hash.""" obj = super(Contributors, self).to_hash(**flags) obj['_id'] = int(self.id) obj['first_name'] = unicode_type(self.first_name) obj['middle_initial'] = unicode_type(self.middle_initial) obj['last_name'] = unicode_type(self.last_name) obj['dept_code'] = unicode_type(self.dept_code) # pylint: disable=no-member obj['person_id'] = int(self.__data__['person']) obj['institution_id'] = int(self.__data__['institution']) # pylint: enable=no-member obj['encoding'] = str(self.encoding) return obj
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(Users, self).to_hash(**flags) obj['_id'] = int(self.id) obj['first_name'] = unicode_type(self.first_name) obj['middle_initial'] = unicode_type(self.middle_initial) obj['last_name'] = unicode_type(self.last_name) if self.network_id is not None: obj['network_id'] = unicode_type(self.network_id).lower() else: obj['network_id'] = None obj['email_address'] = unicode_type(self.email_address) obj['encoding'] = str(self.encoding) return obj
def from_hash(self, obj): """Convert the hash into the object.""" super(Users, self).from_hash(obj) self._set_only_if('_id', obj, 'id', lambda: int(obj['_id'])) for attr in [ 'first_name', 'middle_initial', 'last_name', 'email_address' ]: # pylint: disable=cell-var-from-loop self._set_only_if(attr, obj, attr, lambda: unicode_type(obj[attr])) # pylint: enable=cell-var-from-loop self._set_only_if('network_id', obj, 'network_id', lambda: unicode_type(obj['network_id']).lower()) self._set_only_if('encoding', obj, 'encoding', lambda: str(obj['encoding']))
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(Keys, self).to_hash(**flags) obj['_id'] = int(self.id) obj['key'] = unicode_type(self.key) obj['encoding'] = str(self.encoding) return obj
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(AnalyticalTools, self).to_hash(**flags) obj['_id'] = int(self.id) obj['name'] = unicode_type(self.name) obj['encoding'] = str(self.encoding) return obj
def from_hash(self, obj): """Convert the hash to the object.""" super(Keys, self).from_hash(obj) self._set_only_if('_id', obj, 'id', lambda: obj['_id']) self._set_only_if('key', obj, 'key', lambda: unicode_type(obj['key'])) self._set_only_if('encoding', obj, 'encoding', lambda: str(obj['encoding']))
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(Keywords, self).to_hash(**flags) obj['_id'] = int(self.id) if self.id is not None else obj['_id'] obj['keyword'] = unicode_type(self.keyword) obj['encoding'] = str(self.encoding) return obj
def from_hash(self, obj): """Convert the hash into the object.""" super(Transactions, self).from_hash(obj) self._set_only_if('_id', obj, 'id', lambda: int(obj['_id'])) self._set_only_if('description', obj, 'description', lambda: unicode_type(obj['description'])) self._set_date_part('suspense_date', obj)
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(TransSIP, self).to_hash(**flags) obj['_id'] = int(self.__data__['id']) obj['submitter'] = int(self.__data__['submitter']) obj['instrument'] = int(self.__data__['instrument']) obj['proposal'] = unicode_type(self.__data__['proposal']) return obj
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(Transactions, self).to_hash(**flags) obj['_id'] = int(self.id) if self.id is not None else obj['_id'] obj['description'] = unicode_type(self.__data__['description']) obj['suspense_date'] = str(self.suspense_date.isoformat( )) if self.suspense_date is not None else None return obj
def from_hash(self, obj): """Convert the hash to the object.""" super(AnalyticalTools, self).from_hash(obj) self._set_only_if('_id', obj, 'id', lambda: int(obj['_id'])) self._set_only_if('name', obj, 'name', lambda: unicode_type(obj['name'])) self._set_only_if('encoding', obj, 'encoding', lambda: str(obj['encoding']))
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(Groups, self).to_hash(**flags) obj['_id'] = int(self.id) obj['name'] = unicode_type(self.name) obj['encoding'] = str(self.encoding) obj['is_admin'] = bool(self.is_admin) return obj
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(Journals, self).to_hash(**flags) obj['_id'] = int(self.id) obj['name'] = unicode_type(self.name) obj['impact_factor'] = float(self.impact_factor) obj['website_url'] = str(self.website_url) obj['encoding'] = str(self.encoding) return obj
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(Institutions, self).to_hash(**flags) obj['_id'] = int(self.id) obj['name'] = unicode_type(self.name) obj['association_cd'] = str(self.association_cd) obj['is_foreign'] = bool(self.is_foreign) obj['encoding'] = str(self.encoding) return obj
def to_hash(self, **flags): """Convert the citation fields to a serializable hash.""" exclude_text = flags.get('exclude_text', False) obj = super(Citations, self).to_hash(**flags) obj['_id'] = int(self.id) obj['article_title'] = unicode_type(self.article_title) if not exclude_text: obj['abstract_text'] = unicode_type(self.abstract_text) obj['xml_text'] = unicode_type(self.xml_text) # pylint: disable=no-member obj['journal_id'] = int(self.__data__['journal']) # pylint: enable=no-member obj['journal_volume'] = int(self.journal_volume) obj['journal_issue'] = int(self.journal_issue) obj['page_range'] = str(self.page_range) obj['doi_reference'] = str(self.doi_reference) obj['release_authorization_id'] = str(self.release_authorization_id) obj['encoding'] = str(self.encoding) return obj
def base_where_clause_search_expr(self, obj_hash, **kwargs): """Search for a objects on single search parameters.""" obj = self.base_create_obj(self.obj_cls, obj_hash) chk_obj = self.base_where_clause_search(obj, kwargs)[0] chk_obj_hash = chk_obj.to_hash() for key in obj_hash.keys(): self.assertEqual( chk_obj_hash[key], obj_hash[key], unicode_type('{} not equal to {}').format(chk_obj_hash[key], obj_hash[key]) )
def to_hash(self, **flags): """Convert the object to a hash.""" obj = super(Files, self).to_hash(**flags) obj['_id'] = int(self.id) obj['name'] = unicode_type(self.name) obj['subdir'] = unicode_type(self.subdir) obj['mimetype'] = str(self.mimetype) # pylint: disable=no-member obj['ctime'] = self.ctime.isoformat() obj['mtime'] = self.mtime.isoformat() obj['transaction_id'] = int(self.__data__['transaction']) # pylint: enable=no-member obj['size'] = int(self.size) obj['hashsum'] = str(self.hashsum) obj['hashtype'] = str(self.hashtype) obj['suspense_date'] = str(self.suspense_date.isoformat( )) if self.suspense_date is not None else None obj['encoding'] = str(self.encoding) return obj
def from_hash(self, obj): """Convert the hash into the object.""" super(Institutions, self).from_hash(obj) self._set_only_if('_id', obj, 'id', lambda: int(obj['_id'])) self._set_only_if('name', obj, 'name', lambda: unicode_type(obj['name'])) self._set_only_if('association_cd', obj, 'association_cd', lambda: str(obj['association_cd'])) self._set_only_if('is_foreign', obj, 'is_foreign', lambda: self._bool_translate((obj['is_foreign']))) self._set_only_if('encoding', obj, 'encoding', lambda: str(obj['encoding']))
def from_hash(self, obj): """Convert the hash into the object.""" super(Journals, self).from_hash(obj) self._set_only_if('_id', obj, 'id', lambda: int(obj['_id'])) self._set_only_if('name', obj, 'name', lambda: unicode_type(obj['name'])) self._set_only_if('impact_factor', obj, 'impact_factor', lambda: float(obj['impact_factor'])) self._set_only_if('website_url', obj, 'website_url', lambda: str(obj['website_url'])) self._set_only_if('encoding', obj, 'encoding', lambda: str(obj['encoding']))
def to_hash(self, **flags): """Convert the object to a hash.""" exclude_text = flags.get('exclude_text', False) obj = super(Proposals, self).to_hash(**flags) obj['_id'] = unicode_type(self.id) obj['title'] = unicode_type(self.title) obj['short_name'] = unicode_type(self.short_name) def _set_only_if(attr, expr, true_value, else_func): obj[attr] = true_value if expr else else_func() obj['science_theme'] = unicode_type(self.science_theme) obj['proposal_type'] = unicode_type(self.proposal_type) obj['submitted_date'] = self.submitted_date.isoformat() # pylint: disable=unnecessary-lambda _set_only_if('abstract', exclude_text, None, lambda: unicode_type(self.abstract)) _set_only_if('actual_start_date', self.actual_start_date is None, None, lambda: self.actual_start_date.isoformat()) _set_only_if('accepted_date', self.accepted_date is None, None, lambda: self.accepted_date.isoformat()) _set_only_if('actual_end_date', self.actual_end_date is None, None, lambda: self.actual_end_date.isoformat()) _set_only_if('closed_date', self.closed_date is None, None, lambda: self.closed_date.isoformat()) _set_only_if('suspense_date', self.suspense_date is None, None, lambda: self.suspense_date.isoformat()) # pylint: enable=unnecessary-lambda obj['encoding'] = str(self.encoding) return obj
def from_hash(self, obj): """Convert the hash into the object.""" super(Groups, self).from_hash(obj) # pylint: disable=invalid-name if '_id' in obj: self.id = int(obj['_id']) # pylint: enable=invalid-name if 'name' in obj: self.name = unicode_type(obj['name']) if 'encoding' in obj: self.encoding = str(obj['encoding']) if 'is_admin' in obj: self.is_admin = self._bool_translate(obj['is_admin'])
def base_create_obj(self, cls, obj_hash): """Create obj based on the class given.""" self.base_create_dep_objs() obj = cls() if 'updated' not in obj_hash: change_date_chk = datetime.utcnow() obj.updated = change_date_chk obj.from_hash(obj_hash) obj.save(force_insert=True) if 'updated' not in obj_hash: self.assertEqual(obj.last_change_date(), unicode_type( change_date_chk.isoformat(' '))) return obj
def from_hash(self, obj): """Convert the hash into the object fields.""" super(Contributors, self).from_hash(obj) self._set_only_if('_id', obj, 'id', lambda: int(obj['_id'])) for attr in ['first_name', 'middle_initial', 'last_name', 'dept_code']: self._set_only_if(attr, obj, attr, lambda k=attr: unicode_type(obj[k])) self._set_only_if('person_id', obj, 'person', lambda: Users.get(Users.id == int(obj['person_id']))) self._set_only_if( 'institution_id', obj, 'institution', lambda: Institutions.get( Institutions.id == int(obj['institution_id']))) self._set_only_if('encoding', obj, 'encoding', lambda: str(obj['encoding']))