Commit d8ae72e8 authored by Mikaël Salson's avatar Mikaël Salson Committed by Vidjil Team

results_file.py, sample_set.py: Move get_sample_set_id to the model

In this way it can be used by any controller not just results_file.py
parent 0a3d11c6
......@@ -11,14 +11,6 @@ if request.env.http_origin:
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
def get_sample_set_id(results_file_id):
sample_set_id = db((db.sequence_file.id == db.results_file.sequence_file_id)
&(db.results_file.id == results_file_id)
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
&(db.sample_set.id == db.sample_set_membership.sample_set_id)
).select(db.sample_set_membership.sample_set_id).first().sample_set_id
return sample_set_id
## return admin_panel
def index():
if auth.is_admin():
......@@ -90,7 +82,7 @@ def run_all_patients():
## display run page result
## need ["results_file_id"]
def info():
sample_set_id = get_sample_set_id(request.vars["results_file_id"])
sample_set_id = get_sample_set_id_from_results_file(request.vars["results_file_id"])
if (auth.can_modify_sample_set(sample_set_id)):
log.info("access results file info", extra={'user_id': auth.user.id,
'record_id': request.vars["results_file_id"],
......@@ -101,7 +93,7 @@ def info():
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def output():
sample_set_id = get_sample_set_id(request.vars["results_file_id"])
sample_set_id = get_sample_set_id_from_results_file(request.vars["results_file_id"])
if (auth.can_view_sample_set(sample_set_id)):
results_id = int(request.vars["results_file_id"])
output_directory = defs.DIR_OUT_VIDJIL_ID % results_id
......@@ -123,7 +115,7 @@ def output():
@cache.action()
def download():
sample_set_id = get_sample_set_id(request.vars["results_file_id"])
sample_set_id = get_sample_set_id_from_results_file(request.vars["results_file_id"])
if auth.can_view_sample_set(sample_set_id):
results_id = int(request.vars["results_file_id"])
directory = defs.DIR_OUT_VIDJIL_ID % results_id
......
......@@ -174,3 +174,15 @@ def get_set_group(sid):
(db.auth_permission.name == PermissionEnum.access.value)
).select().first()
return perm.group_id
def get_sample_set_id_from_results_file(results_file_id):
'''
Return the sample set ID corresponding to a result file ID
'''
sample_set_id = db((db.sequence_file.id == db.results_file.sequence_file_id)
&(db.results_file.id == results_file_id)
&(db.sample_set_membership.sequence_file_id == db.sequence_file.id)
&(db.sample_set.id == db.sample_set_membership.sample_set_id)
).select(db.sample_set_membership.sample_set_id).first().sample_set_id
return sample_set_id
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment