Skip to content

Commit 64cf489

Browse files
Added prep_id as an optional parameter (#3262)
* Added prep_id as an optional parameter Added prep_id as an optional parameter to .../study/description/<study_id>?prep_id=<prep_id>. This will bring up the prep_id workflow page instead of summary information. * Temporarily removing CA check for QIIME2 download * Added error-checking
1 parent d3c5ad2 commit 64cf489

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

qiita_pet/handlers/study_handlers/base.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def get(self, study_id):
2323
study = to_int(study_id)
2424
level = self.get_argument('level', '')
2525
message = self.get_argument('message', '')
26+
prep_id = self.get_argument('prep_id', default=None)
2627

2728
study_info = study_get_req(study, self.current_user.id)
2829
if study_info['status'] != 'success':
@@ -32,6 +33,25 @@ def get(self, study_id):
3233
study_info['level'] = level
3334
study_info['message'] = message
3435

36+
if prep_id:
37+
msg = f"'{prep_id}' is not a valid preparation for this study"
38+
study_info['study_info']['prep_id'] = to_int(prep_id, msg)
39+
40+
# prep_id is an integer - confirm that it's a valid prep_id.
41+
prep_info = study_prep_get_req(study, self.current_user.id)
42+
if prep_info['status'] != 'success':
43+
raise HTTPError(404, reason=prep_info['message'])
44+
45+
prep_ids = []
46+
for prep_type in prep_info['info']:
47+
# prep_type will be either '18S', '16S', or similarly named.
48+
# generate a list of prep-ids from the preps in each list.
49+
prep_ids += [x['id'] for x in prep_info['info'][prep_type]]
50+
51+
if study_info['study_info']['prep_id'] not in prep_ids:
52+
raise HTTPError(400, reason=(f"'{prep_id}' is not a valid "
53+
"preparation for this study"))
54+
3555
self.render("study_base.html", **study_info)
3656

3757

qiita_pet/handlers/study_handlers/tests/test_base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ class StudyIndexHandlerTests(TestHandlerBase):
1717
def test_get_exists(self):
1818
response = self.get('/study/description/1')
1919
self.assertEqual(response.code, 200)
20+
self.assertTrue('study/description/baseinfo' in str(response.body))
2021

2122
def test_get_no_exists(self):
2223
response = self.get('/study/description/245')
2324
self.assertEqual(response.code, 404)
2425

26+
def test_get_prep_page(self):
27+
response = self.get('/study/description/1?prep_id=1')
28+
self.assertEqual(response.code, 200)
29+
self.assertTrue('study/description/prep_template' in
30+
str(response.body))
31+
2532

2633
class StudyBaseInfoAJAX(TestHandlerBase):
2734
# TODO: Missing tests

qiita_pet/handlers/util.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def download_link_or_path(is_local_request, filepath, fp_id, label):
8181
linkify, "<a target=\"_blank\" href=\"http://dx.doi.org/{0}\">{0}</a>")
8282

8383

84-
def to_int(value):
84+
def to_int(value, reason=None):
8585
"""Transforms `value` to an integer
8686
8787
Parameters
@@ -102,8 +102,9 @@ def to_int(value):
102102
try:
103103
res = int(value)
104104
except ValueError:
105-
raise HTTPError(400, reason="%s cannot be converted to an "
106-
"integer" % value)
105+
msg = f"{value} cannot be converted to an integer" if reason is None \
106+
else reason
107+
raise HTTPError(400, reason=msg)
107108
return res
108109

109110

qiita_pet/templates/study_base.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@
6464
// Populate the different sections of the page
6565
populate_data_type_menu_div();
6666
// The initial page to be shown is the base information of the study
67-
populate_main_div("{% raw qiita_config.portal_dir %}/study/description/baseinfo/", { study_id: {{study_info['study_id']}}});
67+
{% if 'prep_id' in study_info %}
68+
populate_main_div("{% raw qiita_config.portal_dir %}/study/description/prep_template/", { prep_id: {{study_info['prep_id']}}, study_id: {{study_info['study_id']}}});
69+
{% else %}
70+
populate_main_div("{% raw qiita_config.portal_dir %}/study/description/baseinfo/", { study_id: {{study_info['study_id']}}});
71+
{% end %}
6872

6973
{% if study_info['num_samples'] > 0 %}
7074
$("#sample-summary-btn").show();

0 commit comments

Comments
 (0)