本文整理汇总了Python中qiita_db.study.StudyPerson类的典型用法代码示例。如果您正苦于以下问题:Python StudyPerson类的具体用法?Python StudyPerson怎么用?Python StudyPerson使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StudyPerson类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, study=None, **kwargs):
super(StudyEditorForm, self).__init__(**kwargs)
# Get people from the study_person table to populate the PI and
# lab_person fields
choices = [(sp.id, u"%s, %s"
% (sp.name.decode('utf-8'),
sp.affiliation.decode('utf-8')))
for sp in StudyPerson.iter()]
choices.insert(0, ('', ''))
self.lab_person.choices = choices
self.principal_investigator.choices = choices
# If a study is provided, put its values in the form
if study:
study_info = study.info
self.study_title.data = study.title.decode('utf-8')
self.study_alias.data = study_info['study_alias'].decode('utf-8')
self.publication_doi.data = ",".join(
[doi for doi, _ in study.publications]).decode('utf-8')
self.study_abstract.data = study_info[
'study_abstract'].decode('utf-8')
self.study_description.data = study_info[
'study_description'].decode('utf-8')
self.principal_investigator.data = study_info[
'principal_investigator'].id
self.lab_person.data = (study_info['lab_person'].id
if study_info['lab_person'] else None)
示例2: test_create_studyperson
def test_create_studyperson(self):
new = StudyPerson.create('SomeDude', '[email protected]', 'affil',
'111 fake street', '111-121-1313')
self.assertEqual(new.id, 4)
obs = self.conn_handler.execute_fetchall(
"SELECT * FROM qiita.study_person WHERE study_person_id = 4")
self.assertEqual(obs, [[4, 'SomeDude', '[email protected]', 'affil',
'111 fake street', '111-121-1313']])
示例3: post
def post(self, *args, **kwargs):
name = self.get_argument('name')
affiliation = self.get_argument('affiliation')
email = self.get_argument('email')
phone = self.get_argument('phone', None)
address = self.get_argument('address', None)
if StudyPerson.exists(name, affiliation):
self.fail('Person already exists', 409)
return
p = StudyPerson.create(name=name, affiliation=affiliation, email=email,
phone=phone, address=address)
self.set_status(201)
self.write({'id': p.id})
self.finish()
示例4: test_post_new_person
def test_post_new_person(self):
body = {'name': 'Boaty McBoatFace', 'affiliation': 'UCSD',
'email': '[email protected]', 'phone': '720-876-5309'}
response = self.post('/api/v1/person', data=body, headers=self.headers)
self.assertEqual(response.code, 201)
obs = json_decode(response.body)
exp = StudyPerson.from_name_and_affiliation(body['name'],
body['affiliation']).id
self.assertEqual(exp, obs['id'])
示例5: get
def get(self, *args, **kwargs):
name = self.get_argument('name', None)
affiliation = self.get_argument('affiliation', None)
if name is None and affiliation is None:
# Retrieve the list of all the StudyPerson
sp = [{'name': p.name, 'affiliation': p.affiliation}
for p in StudyPerson.iter()]
self.write(json_encode(sp))
self.finish()
elif name is not None and affiliation is not None:
try:
p = StudyPerson.from_name_and_affiliation(name, affiliation)
except QiitaDBLookupError:
self.fail('Person not found', 404)
return
self.write({'address': p.address, 'phone': p.phone,
'email': p.email, 'id': p.id})
self.finish()
else:
arg_name = 'name' if name is None else 'affiliation'
raise MissingArgumentError(arg_name)
示例6: test_iter
def test_iter(self):
"""Make sure that each and every StudyPerson is retrieved"""
expected = [
('LabDude', '[email protected]', 'knight lab', '123 lab street',
'121-222-3333'),
('empDude', '[email protected]', 'broad', None, '444-222-3333'),
('PIDude', '[email protected]', 'Wash U', '123 PI street', None)]
for i, person in enumerate(StudyPerson.iter()):
self.assertEqual(person.id, i+1)
self.assertEqual(person.name, expected[i][0])
self.assertEqual(person.email, expected[i][1])
self.assertEqual(person.affiliation, expected[i][2])
self.assertEqual(person.address, expected[i][3])
self.assertEqual(person.phone, expected[i][4])
示例7: test_iter
def test_iter(self):
"""Make sure that each and every StudyPerson is retrieved"""
expected = [
("LabDude", "[email protected]", "knight lab", "123 lab street", "121-222-3333"),
("empDude", "[email protected]", "broad", None, "444-222-3333"),
("PIDude", "[email protected]", "Wash U", "123 PI street", None),
]
for i, person in enumerate(StudyPerson.iter()):
self.assertTrue(person.id == i + 1)
self.assertTrue(person.name == expected[i][0])
self.assertTrue(person.email == expected[i][1])
self.assertTrue(person.affiliation == expected[i][2])
self.assertTrue(person.address == expected[i][3])
self.assertTrue(person.phone == expected[i][4])
示例8: _get_study_person_id
def _get_study_person_id(self, index, new_people_info):
"""Returns the id of the study person, creating if needed
If index < 0, means that we need to create a new study person, and its
information is stored in new_people_info[index]
Parameters
----------
index : int
The index of the study person
new_people_info : list of tuples
The information of the new study persons added through the
interface
Returns
-------
int
the study person id
"""
# If the ID is less than 0, then this is a new person
if index < 0:
return StudyPerson.create(*new_people_info[index]).id
return index
示例9: __init__
def __init__(self, study=None, **kwargs):
super(StudyEditorForm, self).__init__(**kwargs)
# Get people from the study_person table to populate the PI and
# lab_person fields
choices = [(sp.id, "%s, %s" % (sp.name, sp.affiliation))
for sp in StudyPerson.iter()]
choices.insert(0, ('', ''))
self.lab_person.choices = choices
self.principal_investigator.choices = choices
# If a study is provided, put its values in the form
if study:
study_info = study.info
self.study_title.data = study.title
self.study_alias.data = study_info['study_alias']
self.pubmed_id.data = ",".join(study.pmids)
self.study_abstract.data = study_info['study_abstract']
self.study_description.data = study_info['study_description']
self.principal_investigator.data = study_info[
'principal_investigator_id']
self.lab_person.data = study_info['lab_person_id']
示例10: setUp
def setUp(self):
StudyPerson.create('SomeDude', '[email protected]', 'some',
'111 fake street', '111-121-1313')
User.create('[email protected]', 'password')
self.config1 = CONFIG_1
self.config2 = CONFIG_2
示例11: test_create_studyperson_already_exists
def test_create_studyperson_already_exists(self):
obs = StudyPerson.create('LabDude', '[email protected]', 'knight lab')
self.assertEqual(obs.name, 'LabDude')
self.assertEqual(obs.email, '[email protected]')
示例12: test_exists
def test_exists(self):
self.assertTrue(StudyPerson.exists('LabDude', 'knight lab'))
self.assertFalse(StudyPerson.exists('AnotherDude', 'knight lab'))
self.assertFalse(StudyPerson.exists('LabDude', 'Another lab'))
示例13: post
def post(self, study=None):
the_study = None
form_factory = StudyEditorExtendedForm
if study:
# Check study and user access
the_study = self._check_study_exists_and_user_access(study)
# If the study is public, we use the short version of the form
if the_study.status == 'public':
form_factory = StudyEditorForm
# Get the form data from the request arguments
form_data = form_factory()
form_data.process(data=self.request.arguments)
# Get information about new people that need to be added to the DB
new_people_info = zip(self.get_arguments('new_people_names'),
self.get_arguments('new_people_emails'),
self.get_arguments('new_people_affiliations'),
self.get_arguments('new_people_phones'),
self.get_arguments('new_people_addresses'))
# New people will be indexed with negative numbers, so we reverse
# the list here
new_people_info.reverse()
index = int(form_data.data['principal_investigator'][0])
if index < 0:
# If the ID is less than 0, then this is a new person
PI = StudyPerson.create(
new_people_info[index][0],
new_people_info[index][1],
new_people_info[index][2],
new_people_info[index][3] or None,
new_people_info[index][4] or None).id
else:
PI = index
if form_data.data['lab_person'][0]:
index = int(form_data.data['lab_person'][0])
if index < 0:
# If the ID is less than 0, then this is a new person
lab_person = StudyPerson.create(
new_people_info[index][0],
new_people_info[index][1],
new_people_info[index][2],
new_people_info[index][3] or None,
new_people_info[index][4] or None).id
else:
lab_person = index
else:
lab_person = None
# TODO: Get the portal type from... somewhere
# TODO: MIXS compliant? Always true, right?
info = {
'portal_type_id': 1,
'lab_person_id': lab_person,
'principal_investigator_id': PI,
'metadata_complete': False,
'mixs_compliant': True,
'study_description': form_data.data['study_description'][0],
'study_alias': form_data.data['study_alias'][0],
'study_abstract': form_data.data['study_abstract'][0]}
if 'timeseries' in form_data.data and form_data.data['timeseries']:
info['timeseries_type_id'] = form_data.data['timeseries'][0]
study_title = form_data.data['study_title'][0]
if the_study:
# We are under editing, so just update the values
the_study.title = study_title
the_study.info = info
msg = ('Study <a href="/study/description/%d">%s</a> '
'successfully updated' %
(the_study.id, form_data.data['study_title'][0]))
else:
# create the study
# TODO: Fix this EFO once ontology stuff from emily is added
the_study = Study.create(User(self.current_user), study_title,
efo=[1], info=info)
msg = ('Study <a href="/study/description/%d">%s</a> '
'successfully created' %
(the_study.id, form_data.data['study_title'][0]))
# Add the environmental packages
if ('environmental_packages' in form_data.data and
form_data.data['environmental_packages']):
the_study.environmental_packages = form_data.data[
'environmental_packages']
if form_data.data['pubmed_id'][0]:
# The user can provide a comma-seprated list
pmids = form_data.data['pubmed_id'][0].split(',')
# Make sure that we strip the spaces from the pubmed ids
the_study.pmids = [pmid.strip() for pmid in pmids]
self.render('index.html', message=msg, level='success',
#.........这里部分代码省略.........
示例14: test_create_studyperson
def test_create_studyperson(self):
new = StudyPerson.create("SomeDude", "[email protected]", "affil", "111 fake street", "111-121-1313")
self.assertEqual(new.id, 4)
obs = self.conn_handler.execute_fetchall("SELECT * FROM qiita.study_person WHERE study_person_id = 4")
self.assertEqual(obs, [[4, "SomeDude", "[email protected]", "affil", "111 fake street", "111-121-1313"]])