当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.delete方法代码示例

本文整理汇总了Python中biorepo.model.DBSession.delete方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.delete方法的具体用法?Python DBSession.delete怎么用?Python DBSession.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在biorepo.model.DBSession的用法示例。


在下文中一共展示了DBSession.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: change_bis_sample

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import delete [as 别名]
    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()
开发者ID:bbcf,项目名称:biorepo,代码行数:33,代码来源:root.py

示例2: delete

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import delete [as 别名]
    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')
开发者ID:bbcf,项目名称:biorepo,代码行数:18,代码来源:project.py

示例3: delete

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import delete [as 别名]
    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')
开发者ID:bbcf,项目名称:biorepo,代码行数:24,代码来源:sample.py

示例4: multi_meas_delete

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import delete [as 别名]
    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."
开发者ID:bbcf,项目名称:biorepo,代码行数:56,代码来源:root.py


注:本文中的biorepo.model.DBSession.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。