@@ -156,21 +156,54 @@ def get(self, analysis_id):
156156 dropped [data_type ].append ({'study' : Study (study ).title ,
157157 'samples' : samples })
158158
159- self .render ("analysis_results.html" ,
159+ self .render ("analysis_results.html" , analysis_id = analysis_id ,
160160 jobres = jobres , aname = analysis .name , dropped = dropped ,
161161 basefolder = get_db_files_base_dir ())
162162
163+ @authenticated
164+ def post (self , analysis_id ):
165+ analysis_id = int (analysis_id .split ("/" )[0 ])
166+ analysis_id_sent = int (self .get_argument ('analysis_id' ))
167+ action = self .get_argument ('action' )
168+
169+ if analysis_id != analysis_id_sent or action != 'delete_analysis' :
170+ raise QiitaPetAuthorizationError (
171+ self .current_user .id ,
172+ 'analysis/results/%d-delete' % analysis_id )
173+
174+ analysis = Analysis (analysis_id )
175+ check_analysis_access (self .current_user , analysis )
176+
177+ try :
178+ Analysis .delete (analysis_id )
179+ msg = ("Analysis <b><i>%s</i></b> has been deleted." % (
180+ analysis .title ))
181+ msg_level = "success"
182+ except Exception as e :
183+ print e
184+ msg = ("Couldn't remove <b><i>%s</i></b> analysis: %s" % (
185+ analysis .name , str (e )))
186+ msg_level = "danger"
187+
188+ # redirecting to list of analysis but also passing messages and
189+ # we need to change the request.method to GET
190+ self .request .method = 'GET'
191+ ShowAnalysesHandler (self .application , self .request )._execute (
192+ [t (self .request ) for t in self .application .transforms ],
193+ message = msg , msg_level = msg_level )
194+
163195
164196class ShowAnalysesHandler (BaseHandler ):
165197 """Shows the user's analyses"""
166198 @authenticated
167- def get (self ):
199+ def get (self , message = '' , msg_level = '' ):
168200 user = self .current_user
169201
170202 analyses = [Analysis (a ) for a in
171203 user .shared_analyses | user .private_analyses ]
172204
173- self .render ("show_analyses.html" , analyses = analyses )
205+ self .render ("show_analyses.html" , analyses = analyses , message = message ,
206+ msg_level = msg_level )
174207
175208
176209class ResultsHandler (StaticFileHandler , BaseHandler ):
0 commit comments