def change_bis_sample(self, sending_s, reception_s): ''' Allow to move all the measurements of one sample to an other one and delete the sending sample after the operation. Usefull for the "_bis" samples in spreadsheet. @param principal : sending_s (sample id sending the measurements), reception_s (sample id receptioning the measurements) ''' try: # samples queries from_sample = DBSession.query(Samples).filter(Samples.id == int(sending_s)).first() to_sample = DBSession.query(Samples).filter(Samples.id == int(reception_s)).first() # get the measurements lists from_att = from_sample.attributs to_att = to_sample.attributs # lab checking if from_att[0].lab_id != to_att[0].lab_id: raise Exception("Samples from different labs. Impossible to move these measurements.") # get list of measurements objects meas_to_move = from_sample.measurements meas_in_place = to_sample.measurements # move the measurements for m in meas_to_move: if m not in meas_in_place: (to_sample.measurements).append(m) DBSession.delete(from_sample) DBSession.add(to_sample) DBSession.flush() print "---> Sample " + sending_s + " was deleted and its measurements are now into the sample " + reception_s except: print_traceback()
def delete(self, *args, **kw): user = handler.user.get_user_in_session(request) project = DBSession.query(Projects).filter(Projects.id == args[0]).first() admin = isAdmin(user) if project.user_id == user.id or admin: try: flash("Your project " + str(project.project_name) + " has been deleted with success") except: flash("Your project " + (project.project_name) + " has been deleted with success") DBSession.delete(project) DBSession.flush() raise redirect('/projects') else: flash("It is not your project -> you are not allowed to delete it", 'error') raise redirect('/projects')
def delete(self, *args, **kw): user = handler.user.get_user_in_session(request) sample = DBSession.query(Samples).filter(Samples.id == args[0]).first() admin = isAdmin(user) if sample.get_userid == user.id or admin: try: flash("Your sample " + str(sample.name) + " has been deleted with success") except: flash("Your sample " + (sample.name) + " has been deleted with success") DBSession.delete(sample) DBSession.flush() raise redirect("/samples") #TO CHECK : check if sample get already an user as owner elif sample.get_userid == None or admin: DBSession.delete(sample) DBSession.flush() flash("Your sample has been deleted") raise redirect("/samples") else: flash("It is not your sample -> you are not allowed to delete it", 'error') raise redirect('/samples')
def multi_meas_delete(self, p_id, s_id, mail, key): ''' deleted ALL the measurements for a given sample /!\ IRREVERSIBLE /!\ ''' try: project = DBSession.query(Projects).filter(Projects.id == p_id).first() sample = DBSession.query(Samples).filter(Samples.id == s_id).first() user = DBSession.query(User).filter(User._email == mail).first() #checking print "--- Check your inputs... ---" if project is None: print "Project " + str(p_id) + " not found." if sample is None: print "Sample " + str(s_id) + " not found." if user is None: print "Your mail " + mail + " is not recorded in BioRepo." if project.id == sample.project_id and user.id == project.user_id: print "--- Begin the purge... ---" list_meas = sample.measurements print "Today, " + str(len(list_meas)) + " will die..." print "--------------------------" for m in list_meas: list_fus = m.fus for f in list_fus: #delete the file on the server only if it is not used by anyone else anymore if len(f.measurements) == 1 and not (f.path).startswith(HTS_path_data()) and not (f.path).startswith(HTS_path_archive()): path_fu = f.path + "/" + f.sha1 mail = user._email mail_tmp = mail.split('@') path_mail = "AT".join(mail_tmp) path_symlink = f.path + "/" + path_mail + "/" + f.sha1 DBSession.delete(f) path_symlink = f.path + "/" + path_mail + "/" + f.sha1 try: os.remove(path_symlink) except: print "---- path_symlink deleted yet ----" pass os.remove(path_fu) elif (f.path).startswith(HTS_path_data()) or (f.path).startswith(HTS_path_archive()): DBSession.delete(f) #TODO send back something to hts to notify that it's not into biorepo anymore print str(m.name) + "(" + str(m.id) + ") ... Sorry ... PAN." DBSession.delete(m) DBSession.flush() print "--- They are all died T_T ---" else: print "It's not your project/sample. The FBI was notified. Run." except: print_traceback() print "Something went wrong...Please, don't cry."