[879b32]: / qiita_pet / handlers / study_handlers / artifact.py

Download this file

148 lines (121 with data), 6.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The Qiita Development Team.
#
# Distributed under the terms of the BSD 3-clause License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from tornado.web import authenticated
from qiita_pet.handlers.util import to_int
from qiita_pet.handlers.base_handlers import BaseHandler
from qiita_pet.handlers.api_proxy import (
artifact_graph_get_req, artifact_types_get_req, artifact_post_req,
artifact_status_put_req, artifact_get_req, artifact_get_prep_req,
artifact_get_info)
from qiita_core.util import execute_as_transaction
from qiita_core.qiita_settings import qiita_config
class ArtifactGraphAJAX(BaseHandler):
@authenticated
def get(self):
direction = self.get_argument('direction')
artifact = to_int(self.get_argument('artifact_id'))
self.write(artifact_graph_get_req(artifact, direction,
self.current_user.id))
class NewArtifactHandler(BaseHandler):
@authenticated
def get(self):
study_id = self.get_argument("study_id")
prep_id = self.get_argument("prep_template_id")
artifact_types = [(at, desc) for at, desc, _, _, is_user_uploadable in
artifact_types_get_req()['types']
if is_user_uploadable]
self.render("study_ajax/add_artifact.html",
study_id=study_id, prep_id=prep_id,
artifact_types=artifact_types)
@authenticated
@execute_as_transaction
def post(self):
artifact_type = self.get_argument('artifact-type')
name = self.get_argument('name')
prep_id = self.get_argument('prep-template-id')
artifact_id = self.get_argument('import-artifact')
# Request the rest of the arguments, which will be the files
files = dict()
for arg in self.request.arguments:
if arg not in ['name', 'prep-template-id', 'artifact-type',
'import-artifact']:
arg_name = arg
# removing ending [], in case they exist, necessary for JS
# array transformation
if arg_name.endswith('[]'):
arg_name = arg_name[:-2]
files[arg_name] = self.get_argument(arg)
artifact = artifact_post_req(
self.current_user.id, files, artifact_type, name, prep_id,
artifact_id)
self.write(artifact)
class ArtifactGetSamples(BaseHandler):
@authenticated
def get(self):
aids = map(int, self.request.arguments.get('ids[]', []))
response = artifact_get_prep_req(self.current_user.id, aids)
self.write(response)
class ArtifactGetInfo(BaseHandler):
@authenticated
def post(self):
aids = map(int, self.request.arguments.get('ids[]', []))
only_biom = self.get_argument('only_biom', 'True') == 'True'
response = artifact_get_info(self.current_user.id, aids, only_biom)
self.write(response)
class ArtifactAdminAJAX(BaseHandler):
@authenticated
def get(self):
artifact_id = to_int(self.get_argument('artifact_id'))
info = artifact_get_req(self.current_user.id, artifact_id)
status = info['visibility']
buttons = []
btn_base = ('<button onclick="set_admin_visibility(\'%s\', {0})" '
'class="btn btn-primary">%s</button>').format(artifact_id)
if qiita_config.require_approval:
if status == 'sandbox':
# The request approval button only appears if the processed
# data issandboxed and the qiita_config specifies that the
# approval should be requested
buttons.append(
btn_base % ('awaiting_approval', 'Request approval'))
elif self.current_user.level == 'admin' and \
status == 'awaiting_approval':
# The approve processed data button only appears if the user is
# an admin, the processed data is waiting to be approved and
# the qiita config requires processed data approval
buttons.append(btn_base % ('private', 'Approve artifact'))
if status == 'private':
# The make public button only appears if the status is private
buttons.append(btn_base % ('public', 'Make public'))
# The revert to sandbox button only appears if the processed data is
# not sandboxed or public
if status not in {'sandbox', 'public'}:
buttons.append(btn_base % ('sandbox', 'Revert to sandbox'))
# Add EBI and VAMPS submission buttons if allowed
if not info['ebi_run_accessions'] and info['can_submit_ebi']:
buttons.append('<a class="btn btn-primary glyphicon '
'glyphicon-export" href="/ebi_submission/{{ppd_id}}'
'" style="word-spacing: -10px;"> Submit to EBI</a>')
if not info['is_submitted_vamps'] and \
info['can_submit_vamps']:
buttons.append('<a class="btn btn-primary glyphicon '
'glyphicon-export" href="/vamps/{{ppd_id}}" '
'style="word-spacing: -10px;"> Submit to VAMPS</a>')
# Add delete button if in sandbox status
if status == 'sandbox':
buttons = ['<button class="btn btn-danger" '
'onclick="delete_artifact(%d)">Delete Artifact</button>'
% (artifact_id)]
self.write(' '.join(buttons))
@authenticated
def post(self):
visibility = self.get_argument('visibility')
artifact_id = int(self.get_argument('artifact_id'))
response = artifact_status_put_req(artifact_id, self.current_user.id,
visibility)
self.write(response)