Exemplo n.º 1
0
    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']))

        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)
Exemplo n.º 2
0
 def to_hash(self, recursion_depth=1):
     """Convert the object to a hash."""
     obj = super(Instruments, self).to_hash(recursion_depth)
     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
Exemplo n.º 3
0
 def to_hash(self, recursion_depth=1):
     """Convert the object fields into a serializable hash."""
     obj = super(Contributors, self).to_hash(recursion_depth)
     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.person.id)
     obj['institution_id'] = int(self.institution.id)
     # pylint: enable=no-member
     obj['encoding'] = str(self.encoding)
     return obj
Exemplo n.º 4
0
 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']))
Exemplo n.º 5
0
 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']))
Exemplo n.º 6
0
 def to_hash(self):
     """Convert the object to a hash."""
     obj = super(Users, self).to_hash()
     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
Exemplo n.º 7
0
 def to_hash(self):
     """Convert the object to a hash."""
     obj = super(Values, self).to_hash()
     obj['_id'] = int(self.id)
     obj['value'] = unicode_type(self.value)
     obj['encoding'] = str(self.encoding)
     return obj
Exemplo n.º 8
0
 def to_hash(self, recursion_depth=1):
     """Convert the object to a hash."""
     obj = super(AnalyticalTools, self).to_hash(recursion_depth)
     obj['_id'] = int(self.id)
     obj['name'] = unicode_type(self.name)
     obj['encoding'] = str(self.encoding)
     return obj
Exemplo n.º 9
0
 def to_hash(self, recursion_depth=1):
     """Convert the object to a hash."""
     obj = super(Keywords, self).to_hash(recursion_depth)
     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
Exemplo n.º 10
0
 def to_hash(self):
     """Convert the object to a hash."""
     obj = super(Keys, self).to_hash()
     obj['_id'] = int(self.id)
     obj['key'] = unicode_type(self.key)
     obj['encoding'] = str(self.encoding)
     return obj
Exemplo n.º 11
0
 def to_hash(self, recursion_depth=1):
     """Convert the object to a hash."""
     obj = super(Files, self).to_hash(recursion_depth)
     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.transaction.id)
     # pylint: enable=no-member
     obj['size'] = int(self.size)
     obj['hashsum'] = str(self.hashsum)
     obj['hashtype'] = str(self.hashtype)
     obj['encoding'] = str(self.encoding)
     return obj
Exemplo n.º 12
0
 def from_hash(self, obj):
     """Convert the hash to the object."""
     super(Keywords, self).from_hash(obj)
     self._set_only_if('_id', obj, 'id', lambda: int(obj['_id']))
     self._set_only_if('keyword', obj, 'keyword',
                       lambda: unicode_type(obj['keyword']))
     self._set_only_if('encoding', obj, 'encoding',
                       lambda: str(obj['encoding']))
Exemplo n.º 13
0
 def to_hash(self, recursion_depth=1):
     """Convert the object to a hash."""
     obj = super(Groups, self).to_hash(recursion_depth)
     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
Exemplo n.º 14
0
 def to_hash(self, recursion_depth=1):
     """Convert the citation fields to a serializable hash."""
     obj = super(Citations, self).to_hash(recursion_depth)
     obj['_id'] = int(self.id)
     obj['article_title'] = unicode_type(self.article_title)
     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.journal.id)
     # 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 to_hash(self):
     """Convert the object to a hash."""
     obj = super(Transactions, self).to_hash()
     obj['_id'] = int(self.id) if self.id is not None else obj['_id']
     obj['submitter'] = int(self.submitter.id)
     obj['instrument'] = int(self.instrument.id)
     obj['proposal'] = unicode_type(self.proposal.id)
     return obj
Exemplo n.º 16
0
 def to_hash(self, recursion_depth=1):
     """Convert the object to a hash."""
     obj = super(Institutions, self).to_hash(recursion_depth)
     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
Exemplo n.º 17
0
 def to_hash(self):
     """Convert the object to a hash."""
     obj = super(Journals, self).to_hash()
     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
Exemplo n.º 18
0
 def to_hash(self, recursion_depth=1):
     """Convert the object to a hash."""
     obj = super(Proposals, self).to_hash(recursion_depth)
     obj['_id'] = unicode_type(self.id)
     obj['title'] = unicode_type(self.title)
     obj['abstract'] = unicode_type(self.abstract)
     obj['science_theme'] = unicode_type(self.science_theme)
     obj['proposal_type'] = unicode_type(self.proposal_type)
     obj['submitted_date'] = self.submitted_date.isoformat()
     obj['actual_start_date'] = self.actual_start_date.isoformat() \
         if self.actual_start_date is not None else None
     obj['accepted_date'] = self.accepted_date.isoformat() \
         if self.accepted_date is not None else None
     obj['actual_end_date'] = self.actual_end_date.isoformat() \
         if self.actual_end_date is not None else None
     obj['closed_date'] = self.closed_date.isoformat() \
         if self.closed_date is not None else None
     obj['encoding'] = str(self.encoding)
     return obj
Exemplo n.º 19
0
 def from_hash(self, obj):
     """Convert the hash to the object."""
     super(Proposals, self).from_hash(obj)
     self._set_only_if('_id', obj, 'id', lambda: unicode_type(obj['_id']))
     self._set_only_if('title', obj, 'title',
                       lambda: unicode_type(obj['title']))
     self._set_only_if('abstract', obj, 'abstract',
                       lambda: unicode_type(obj['abstract']))
     self._set_only_if('science_theme', obj, 'science_theme',
                       lambda: unicode_type(obj['science_theme']))
     self._set_only_if('proposal_type', obj, 'proposal_type',
                       lambda: unicode_type(obj['proposal_type']))
     self._set_only_if('encoding', obj, 'encoding',
                       lambda: str(obj['encoding']))
     self._set_datetime_part('submitted_date', obj)
     self._set_date_part('accepted_date', obj)
     self._set_date_part('actual_start_date', obj)
     self._set_date_part('actual_end_date', obj)
     self._set_date_part('closed_date', obj)
Exemplo n.º 20
0
 def from_hash(self, obj):
     """Convert the hash to the object."""
     super(Keys, self).from_hash(obj)
     if '_id' in obj:
         # pylint: disable=invalid-name
         self.id = obj['_id']
         # pylint: enable=invalid-name
     if 'key' in obj:
         self.key = unicode_type(obj['key'])
     if 'encoding' in obj:
         self.encoding = str(obj['encoding'])
Exemplo n.º 21
0
 def from_hash(self, obj):
     """Convert the hash to the object."""
     super(AnalyticalTools, self).from_hash(obj)
     if '_id' in obj:
         # pylint: disable=invalid-name
         self.id = 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'])
Exemplo n.º 22
0
 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']))
Exemplo n.º 23
0
 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']))
Exemplo n.º 24
0
 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']))
Exemplo n.º 25
0
 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'])
Exemplo n.º 26
0
 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
Exemplo n.º 27
0
 def from_hash(self, obj):
     """Convert the object into the citation object fields."""
     super(Citations, self).from_hash(obj)
     self._set_only_if('_id', obj, 'id', lambda: int(obj['_id']))
     self._set_only_if(
         'journal_id', obj, 'journal',
         lambda: Journals.get(Journals.id == int(obj['journal_id'])))
     for key in ['journal_volume', 'journal_issue']:
         self._set_only_if(key, obj, key, lambda k=key: int(obj[k]))
     for key in [
             'page_range', 'release_authorization_id', 'encoding',
             'doi_reference'
     ]:
         self._set_only_if(key, obj, key, lambda k=key: str(obj[k]))
     for key in ['article_title', 'xml_text', 'abstract_text']:
         self._set_only_if(key,
                           obj,
                           key,
                           lambda k=key: unicode_type(obj[k]))