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


Python DBSession.add方法代码示例

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


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

示例1: change_project_owner

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
    def change_project_owner(self, p_id, new_owner_id, mail, key):
        '''
        Allow to change the owner of one given project (include its sample(s) and measurement(s))
        '''
        try:
            p_target = DBSession.query(Projects).filter(Projects.id == p_id).first()
            #just one lab by project, so the first is the good one
            project_lab = p_target.labs[0]
            new_owner = DBSession.query(User).filter(User.id == new_owner_id).first()
            if project_lab in new_owner.labs:
                list_samples = p_target.samples
                for s in list_samples:
                    list_meas = s.measurements
                    for m in list_meas:
                        m.user_id = new_owner.id
                        DBSession.add(m)
                        DBSession.flush()
                p_target.user_id = new_owner.id
                DBSession.add(p_target)
                DBSession.flush()
                print "Update done."

            else:
                raise Exception("The new owner is not a member of this lab project. Impossible to continue the operation.")
        except:
            print_traceback()
开发者ID:bbcf,项目名称:biorepo,代码行数:28,代码来源:root.py

示例2: change_bis_sample

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [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

示例3: post

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
 def post(self, *args, **kw):
     user = handler.user.get_user_in_session(request)
     user_lab = session.get("current_lab", None)
     if user_lab:
         lab = DBSession.query(Labs).filter(Labs.name == user_lab).first()
     p = Projects()
     if kw['project_name'] == '':
         flash("Bad Project : Your project must have a name", "error")
         raise redirect("./new")
     p.project_name = kw['project_name']
     p.user_id = user.id
     p.description = kw.get('description', None)
     (p.labs).append(lab)
     DBSession.add(p)
     DBSession.flush()
     flash("Project created !")
     raise redirect('/projects')
开发者ID:bbcf,项目名称:biorepo,代码行数:19,代码来源:project.py

示例4: create_ext_lab

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
 def create_ext_lab(self, mail, key, lab_name):
     #utilisation (only for admins) :
     #wget --post-data "[email protected]&key=xxxxxxxxxxx&lab_name=bbcf" http://yourdomain.com/biorepo/create_ext_lab
     lab_test = DBSession.query(Labs).filter(Labs.name == lab_name).first()
     if lab_test is None:
         try:
             lab = Labs()
             lab.name = lab_name
             lab.path_raw = path_raw(lab_name)
             lab.path_processed = path_processed(lab_name)
             lab.path_tmp = path_tmp(lab_name)
             DBSession.add(lab)
             DBSession.flush()
             print "Exterior lab created :", lab_name
         except:
             print_traceback()
             print "Exterior lab NOT created --> ERROR"
     else:
         print "This lab : ", str(lab_name), " is in the db yet. --> ERROR"
开发者ID:bbcf,项目名称:biorepo,代码行数:21,代码来源:root.py

示例5: create_gone_user

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
 def create_gone_user(self, mail, key, lab_id, firstname, name, user_mail):
     #utilisation (only for admins) :
     #wget --post-data "key=xxxxxxxxxxxxxxxxxxxxx&[email protected]&lab_id=lab_id&firstname=jean-michel&name=michel&[email protected]" \
     # http://yourdomain.com/biorepo/create_gone_user
     try:
         user = User()
         user.firstname = firstname.capitalize()
         user.name = name.capitalize()
         lab = DBSession.query(Labs).filter(Labs.id == lab_id).first()
         user.labs.append(lab)
         user._email = user_mail
         group = DBSession.query(Group).filter(Group.id == 1).first()
         user.groups.append(group)
         DBSession.add(user)
         DBSession.flush()
         print "Gone/Exterior user created :", user
     except:
         print_traceback()
         print "Gone/Exterior user NOT created --> ERROR"
开发者ID:bbcf,项目名称:biorepo,代码行数:21,代码来源:root.py

示例6: check_value_addition

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
    def check_value_addition(self, list_type_att, dict_att_values_type, dict_att_values_db, lab_id):
        '''
        Checking for value(s) addition
        @param principal
        @return an updated db
        '''
        for key_type in list_type_att:
            for i in dict_att_values_type[key_type]:
                #get the attribut and its value(s)
                i_att = DBSession.query(Attributs).filter(and_(Attributs.lab_id == lab_id, Attributs.key == key_type)).first()
                #warning : i_att_value is a list !
                i_att_value = DBSession.query(Attributs_values).filter(and_(Attributs_values.attribut_id == i_att.id,
                Attributs_values.value == i)).all()
                try:
                    flag = False
                    if i not in dict_att_values_db[key_type] and i != "None":
                        for existant in i_att_value:
                            if existant.value == i and existant.deprecated == True:
                                existant.deprecated = False
                                DBSession.flush()
                                flag = True
                            if existant.value is None:
                                existant.deprecated = True
                                DBSession.flush()
                        if flag == False:
                            new_value = Attributs_values()
                            new_value.attribut_id = i_att.id
                            new_value.value = i
                            new_value.deprecated = False
                            DBSession.add(new_value)
                            DBSession.flush()

                except Exception as e:
                    import sys, traceback
                    a, b, c = sys.exc_info()
                    traceback.print_exception(a, b, c)
                    print "--- error login.py check_value_addition() ---"
                    print "i --->", i
                    print "key_type --->", key_type
                    print "list_type_att --->", list_type_att
                    print "dict_att_values_type[key_type] -->", dict_att_values_type[key_type]
                    print "i_att --> ", i_att
                    print "i_att_value", i_att_value
开发者ID:bbcf,项目名称:biorepo,代码行数:45,代码来源:login.py

示例7: create

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
    def create(self, *args, **kw):
        user = handler.user.get_user_in_session(request)
        project = Projects()
        name = kw.get('project_name', None)
        if name is None:
            return {'ERROR': "You have to give a name to your project"}
        project.project_name = name
        lab_id = kw['lab']
        if lab_id is None:
            return {'ERROR': "We need to know the user's lab"}
        lab = DBSession.query(Labs).filter(Labs.id == lab_id).first()
        (project.labs).append(lab)
        #test if user is an admin
        admin = isAdmin(user)
        if admin:
            project.user_id = kw.get('user_id', user.id)
        else:
            project.user_id = user.id

        project.description = kw.get('description', None)
        get_samples = kw.get('samples', None)
        l = []

        if get_samples is None:
            project.samples = l
        else:
            for x in get_samples.split(','):
                sam = DBSession.query(Samples).join(Projects).join(User).filter(Samples.id == x).first()
                l.append(sam)

            project.samples = l
        #checking print
        print project, " building project with wget"

        DBSession.add(project)
        DBSession.flush()

        return {"user_id": user.id, "user_name": user.name, "project_id": project.id, "project_name": project.project_name,
                 "description": project.description}
开发者ID:bbcf,项目名称:biorepo,代码行数:41,代码来源:project.py

示例8: manage_fu_from_HTS

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
def manage_fu_from_HTS(existing_fu, meas, filename, sha1, url_path, hts_path):

    #fixing bug str "true", str "false" for meas.type
    if isinstance(meas.type, basestring):
        bool_type = str2bool(meas.type)
        meas.type = bool_type

    if existing_fu:
        print "-------- EXISTING FILE FROM HTS--------"
        meas.fus.append(existing_fu)

        DBSession.add(meas)
        DBSession.flush()
        return existing_fu
        ###########################################################################################
    else:
        #new files_up building
        fu = Files_up()
        fu.path = hts_path
        #save the filename and the extension to the database
        fu.filename = filename
        if '.' in filename:
            extension = filename.split('.')[-1]
            fu.extension = extension
        else:
            fu.extension = "not specified"
        fu.sha1 = sha1
        fu.url_path = url_path

        #add to the crossing table (measurement <-> file uploaded)
        meas.fus.append(fu)

        #adding new measurement and new files_up to the db
        DBSession.add(meas)
        DBSession.add(fu)
        DBSession.flush()
        return fu
开发者ID:bbcf,项目名称:biorepo,代码行数:39,代码来源:util.py

示例9: post_edit

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
    def post_edit(self, *args, **kw):
        id_sample = kw['IDselected']
        sample = DBSession.query(Samples).filter(Samples.id == id_sample).first()
        try:
            project_id = kw.get("project")
            if project_id is None or project_id == "":
                flash("Edition rejected : Your sample must be in a project", 'error')
                raise redirect("./")
            sample.project_id = project_id
        except:
            flash("Your sample must be in a project", 'error')
            raise redirect("./")

        if kw['name'] == '' or kw['name'] is None:
            flash("Bad Sample : you have to give a name to your sample", "error")
            raise redirect("./edit/" + id_sample)
        sample.name = kw.get("name", None)
        sample.protocole = kw.get("protocole", None)
        sample.type = kw.get("type", None)
        meas_ids = kw.get("measurements", None)
        if meas_ids is not None:
            if not isinstance(meas_ids, (list, tuple)):
                meas_ids = [int(meas_ids)]
            else:
                #from unicode to integer for comparison
                list_tmp = []
                for i in meas_ids:
                    i = int(i)
                    list_tmp.append(i)
                meas_ids = list_tmp
        else:
            meas_ids = []
        list_meas = []
        for m in meas_ids:
            measurement = DBSession.query(Measurements).filter(Measurements.id == m).first()
            list_meas.append(measurement)
        sample.measurements = list_meas

        #DYNAMICITY
        list_static = ['project', 'name', 'type', 'protocole', 'IDselected', 'measurements']
        list_attributs = []
        list_a_values = sample.a_values
        for a in sample.attributs:
            if a.deprecated == False:
                list_attributs.append(a)

        for x in kw:
            if x not in list_static:
                for a in list_attributs:
                    if x == a.key:
                        val_kw = kw[x]
                        object_2_delete = None
                        #search if the field was edited
                        for v in list_a_values:
                            v_value = v.value
                            if a.widget == "checkbox" or a.widget == "hiding_checkbox":
                                val_kw = check_boolean(kw[x])
                                v_value = check_boolean(v.value)
                            if v.attribut_id == a.id and v_value != val_kw and a.widget != "multipleselectfield" and a.widget != "hiding_multipleselectfield":
                                object_2_delete = v
                        if a.widget == "textfield" or a.widget == "hiding_textfield" or a.widget == "textarea" or a.widget == "hiding_textarea":
                            if object_2_delete:
                                object_2_delete.value = kw[x]

                        elif a.widget == "checkbox" or a.widget == "hiding_checkbox":
                            if len(a.values) < 3:
                                for old_v in a.values:
                                    if old_v.value is not None and old_v.value != '':
                                        list_a_values.remove(old_v)
                                av = Attributs_values()
                                av.attribut_id = a.id
                                av.value = True
                                av.deprecated = False
                                DBSession.add(av)
                                list_a_values.append(av)
                                DBSession.flush()

                            elif len(a.values) == 3:
                                if object_2_delete:
                                    list_a_values.remove(object_2_delete)
                                    v = object_2_delete.value
                                    for val in a.values:
                                        val_to_avoid = [None, ""]
                                        if v not in val_to_avoid:
                                            val_to_avoid.append(v)
                                        if val.value not in val_to_avoid:
                                            list_a_values.append(val)
                                            DBSession.flush()
                            else:
                                print "----- BOOLEAN ERROR -----"
                                print str(a.id), " attributs id"
                                print "boolean with more than 2 values"
                                raise

                        elif a.widget == "singleselectfield" or a.widget == "hiding_singleselectfield":
                            #edition : delete the connexion to the older a_value, make the connexion between the new a_value and the sample
                            if object_2_delete:
                                list_a_values.remove(object_2_delete)
                                list_possible = a.values
                                for p in list_possible:
#.........这里部分代码省略.........
开发者ID:bbcf,项目名称:biorepo,代码行数:103,代码来源:sample.py

示例10: post

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
    def post(self, *args, **kw):
        user_lab = session.get("current_lab", None)
        lab = DBSession.query(Labs).filter(Labs.name == user_lab).first()
        lab_id = lab.id
        s = Samples()
        list_static = ['project', 'name', 'type', 'protocole']
        list_dynamic = []
        #new sample object
        if 'project' not in kw:
            flash("You have to choose a project to attach to your new sample, retry please", "error")
            raise redirect('./')
        s.project_id = kw['project']
        #TODO : make a correct validator for NewSample
        if kw['name'] == '':
            flash("Bad Sample : you have to give a name to your sample", "error")
            raise redirect('./new')
        s.name = kw['name']
        s.type = kw.get('type', None)
        s.protocole = kw.get('protocole', None)
        DBSession.add(s)
        DBSession.flush()

        #link the new sample to the attributs object
        for x in kw:
            #exclude the static fields belonging to Samples()
            if x not in list_static:
                list_dynamic.append(x)
                #get the attribut
                a = DBSession.query(Attributs).filter(and_(Attributs.lab_id == lab_id, Attributs.key == x, Attributs.deprecated == False, Attributs.owner == "sample")).first()
                if a is not None:
                    #get its value(s)
                    (s.attributs).append(a)
                    #if values of the attribute are fixed
                    if a.fixed_value == True and kw[x] is not None and kw[x] != '' and a.widget != "checkbox" and a.widget != "hiding_checkbox":
                        value = kw[x]
                        list_value = DBSession.query(Attributs_values).filter(Attributs_values.attribut_id == a.id).all()
                        for v in list_value:
                            #if the keyword value is in the value list, the attributs_values object is saved in the cross table
                            if v.value == value and v not in s.a_values:
                                (s.a_values).append(v)
                                DBSession.flush()
                    #if values of the attribute are free
                    elif a.fixed_value == False and a.widget != "checkbox" and a.widget != "hiding_checkbox":
                        av = Attributs_values()
                        av.attribut_id = a.id
                        av.value = kw.get(x, None)
                        av.deprecated = False
                        DBSession.add(av)
                        DBSession.flush()
                        (s.a_values).append(av)
                        DBSession.flush()
                    #special case for checkbox because of the "on" and None value of TW2 for True and False...(here it's True)
                    elif a.widget == "checkbox" or a.widget == "hiding_checkbox":
                        found = False
                        for v in a.values:
                            if check_boolean(v.value) and v.value is not None:
                                (s.a_values).append(v)
                                found = True
                        if not found:
                            av = Attributs_values()
                            av.attribut_id = a.id
                            av.value = True
                            av.deprecated = False
                            DBSession.add(av)
                            DBSession.flush()
                            (s.a_values).append(av)
                            DBSession.flush()

        #special case for checkbox because of the "on" and None value of TW2 for True and False...(here it's False)
        dynamic_booleans = DBSession.query(Attributs).filter(and_(Attributs.lab_id == lab_id, Attributs.deprecated == False, Attributs.owner == "sample", or_(Attributs.widget == "checkbox", Attributs.widget == "hiding_checkbox"))).all()
        if len(dynamic_booleans) > 0:
            for d in dynamic_booleans:
                if d.key not in list_dynamic:
                    if d.widget == "checkbox" or d.widget == "hiding_checkbox":
                        found = False
                        for v in d.values:
                            if not check_boolean(v.value) and v.value is not None:
                                (s.attributs).append(d)
                                (s.a_values).append(v)
                                found = True
                                #to avoid IntegrityError in the db
                                break
                        if not found:
                            av = Attributs_values()
                            av.attribut_id = d.id
                            av.value = False
                            av.deprecated = False
                            DBSession.add(av)
                            DBSession.flush()
                            (s.attributs).append(d)
                            (s.a_values).append(av)
                            DBSession.flush()

        flash("Sample created !")
        raise redirect('/samples')
开发者ID:bbcf,项目名称:biorepo,代码行数:97,代码来源:sample.py

示例11: create

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
    def create(self, *args, **kw):
        user = handler.user.get_user_in_session(request)
        kw['user'] = user.id
        lab = kw.get("lab", None)
        if lab is None:
            return {"ERROR": "We need to know the lab of the user..."}
        sample = Samples()
        if not kw.has_key('project_id'):
            return {"ERROR": "project_id missing"}
        type_ = kw.get('type', None)
        sample.project_id = kw['project_id']
        sample.name = kw.get('name', 'Give me a name please')

        if type_ is not None:
            try:
                ret1 = list_lower(type_, get_list_types(lab))
                sample.type = ret1
            except:
                return {"ERROR": "your " + type_ + " is not known in types list"}
        elif type_ is None:
            sample.type = type_

        sample.protocole = kw.get('protocole', None)

        get_meas = kw.get('measurements', None)
        l = []
        if get_meas is None:
            sample.measurements = l
        else:
            for x in get_meas.split(','):
                meas = DBSession.query(Measurements).filter(Measurements.id == x).first()
                l.append(meas)

            sample.measurements = l
        #print server
        print sample, "building sample with wget"

        #dynamicity
        list_static = ['project', 'name', 'type', 'protocole', 'measurements', 'lab', 'user', 'key', 'mail', 'project_id']
        list_dynamic = []
        labo = DBSession.query(Labs).filter(Labs.name == lab).first()
        lab_id = labo.id

        #save the attributs of the lab for final comparison
        dynamic_keys = []
        lab_attributs = DBSession.query(Attributs).filter(and_(Attributs.lab_id == lab_id, Attributs.deprecated == False, Attributs.owner == "sample")).all()
        for i in lab_attributs:
            dynamic_keys.append(i.key)

        for x in kw:
            #exclude the static fields belonging to Samples()
            if x not in list_static:
                list_dynamic.append(x)
                #get the attribut
                a = DBSession.query(Attributs).filter(and_(Attributs.lab_id == lab_id, Attributs.key == x, Attributs.deprecated == False, Attributs.owner == "sample")).first()
                if a is not None:
                    #get its value(s)
                    (sample.attributs).append(a)
                    #if values of the attribute are fixed
                    if a.fixed_value == True and kw[x] is not None and kw[x] != '' and a.widget != "checkbox" and a.widget != "hiding_checkbox":
                        value = kw[x]
                        list_value = DBSession.query(Attributs_values).filter(and_(Attributs_values.attribut_id == a.id, Attributs_values.deprecated == False)).all()
                        for v in list_value:
                            #if the keyword value is in the value list, the attributs_values object is saved in the cross table
                            if (v.value).lower() == value.lower() and v not in sample.a_values:
                                (sample.a_values).append(v)
                                DBSession.flush()
                    #if values of the attribute are free
                    elif a.fixed_value == False and a.widget != "checkbox" and a.widget != "hiding_checkbox":
                        av = Attributs_values()
                        av.attribut_id = a.id
                        av.value = kw.get(x, None)
                        av.deprecated = False
                        DBSession.add(av)
                        DBSession.flush()
                        (sample.a_values).append(av)
                        DBSession.flush()
                    #special case for checkbox because of the "on" and None value of TW2 for True and False...(here it's True)
                    elif a.widget == "checkbox" or a.widget == "hiding_checkbox":
                        #Why 3 ? Because 3 cases max registred : True, False and None ---> so <3
                        if len(a.values) < 3:
                            av = Attributs_values()
                            av.attribut_id = a.id
                            #for True value, Attribut key and value have to be similar into the excel sheet...
                            if (kw[x]).lower() == x.lower():
                                av.value = True
                            #...and different for the False :)
                            else:
                                av.value = False
                            av.deprecated = False
                            DBSession.add(av)
                            DBSession.flush()
                            (sample.a_values).append(av)
                            DBSession.flush()
                        else:
                            if (kw[x]).lower() == x.lower():
                                for v in a.values:
                                    if check_boolean(v.value) and v.value is not None:
                                        (sample.a_values).append(v)
                            else:
#.........这里部分代码省略.........
开发者ID:bbcf,项目名称:biorepo,代码行数:103,代码来源:sample.py

示例12: manage_fu

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
def manage_fu(existing_fu, meas, public_dirname, filename, sha1, up_data, url_path, url_up, dest_raw, dest_processed, tmp_path, lab):

    tmpdir_to_delete = os.path.abspath(os.path.join(tmp_path, os.path.pardir))
    #fixing bug str "true", str "false" for meas.type
    if isinstance(meas.type, basestring):
        bool_type = str2bool(meas.type)
        meas.type = bool_type

    if existing_fu:
        print "-------- EXISTING FILE --------"
        #create symbolic link
        source = existing_fu.path + "/" + sha1

        if meas.type:
            dest = dest_raw + sha1
            #test symlin existance
            if os.path.islink(dest):
                symlink_e = "This file was already in your personal folder"
            else:
                symlink_e = "This file was added to your personal folder"
                os.symlink(source, dest)

        else:
            dest = dest_processed + sha1
            #test symlink existance
            if os.path.islink(dest):
                symlink_e = "This file was already in your personal folder"
            else:
                symlink_e = "This file was added to your personal folder"
                os.symlink(source, dest)

        meas.fus.append(existing_fu)

        DBSession.add(meas)
        DBSession.flush()

        flash(symlink_e + ", measurement created")
        #remove the tmp file if it didn't come from HTSStation
        if not tmpdir_to_delete.startswith('/data'):
            shutil.rmtree(tmpdir_to_delete)
        #raise redirect("./")
        return existing_fu

        ###########################################################################################
    else:
        #new files_up building
        fu = Files_up()
        #raw test for path orientation
        if meas.type:
            fu.path = path_raw(lab)
            data_dirname = os.path.join(public_dirname, fu.path)
        else:
            fu.path = path_processed(lab)
            data_dirname = os.path.join(public_dirname, fu.path)

        #save the filename and the extension to the database
        fu.filename = filename
        if '.' in filename:
            extension = filename.split('.')[-1]
            fu.extension = extension
#            root, ext = os.path.splitext(filename)
#            DOUBLE_EXTENSIONS = ['tar.gz','tar.bz2','bedGraph.gz','bed.gz']
#            if any([filename.endswith(x) for x in DOUBLE_EXTENSIONS]):
#                root, first_ext = os.path.splitext(root)
#                ext = first_ext + ext
#                fu.extension = ext
#            else:
#                fu.extension = ext
        else:
            fu.extension = "not specified"
        data_path = os.path.join(data_dirname, str(sha1))
        fu.sha1 = sha1
        fu.url_path = url_path

        #writing the file into the server HD
        #version browser
        try:
            with open(data_path, "w") as d:
                if up_data is not None:
                    d.write(up_data.value)
                elif url_path is not None and url_up:

                    u = urllib2.urlopen(url_path)
                    while True:
                        buffer = u.read(8192)
                        if not buffer:
                            break

                        d.write(buffer)
                else:
                    print "ERROR"
        #version commandline
        except:
            shutil.move(tmp_path, data_path)

        #symlink
        source = data_path
        if meas.type:
            dest = dest_raw + sha1
            if os.path.islink(dest):
#.........这里部分代码省略.........
开发者ID:bbcf,项目名称:biorepo,代码行数:103,代码来源:util.py

示例13: auth

# 需要导入模块: from biorepo.model import DBSession [as 别名]
# 或者: from biorepo.model.DBSession import add [as 别名]
    def auth(self, came_from='/', **kw):
        '''
        Fetch user back from tequila.
        Validate the key from tequila.
        Log user.
        '''
        if not kw.has_key('key'):
            raise redirect(came_from)

        # take parameters
        key = kw.get('key')
        environ = request.environ
        authentication_plugins = environ['repoze.who.plugins']
        identifier = authentication_plugins['ticket']
        secret = identifier.secret
        cookiename = identifier.cookie_name
        remote_addr = environ['REMOTE_ADDR']
        # get user
        principal = tequila.validate_key(key, 'tequila.epfl.ch')
        if principal is None:
            raise redirect('./login')

        #in case of user gets several labs
        try:
            if session["first_passage"] == False:
                #second passage
                tmp_user = session["tmp_user"]
                tmp_lab = session['tmp_lab']
        except:
            #first passage
            session["first_passage"] = True
            session["principal_tequila"] = principal
            session.save()
            tmp_user, tmp_lab = self.build_user(principal)
        try:
            mail = tmp_user.email
        except:
            flash("Sorry, you've been disconnected. You can try to relog yourself now", 'error')
            raise redirect('/login/out')
        # log or create him
        user = DBSession.query(User).filter(User.email == tmp_user.email).first()
        if user is None:
            user_group = DBSession.query(Group).filter(Group.name == gl.group_users).first()
            user_group.users.append(tmp_user)
            DBSession.add(tmp_user)
            DBSession.flush()

            user = DBSession.query(User).filter(User.email == mail).first()
            flash(u'Your account has been created  %s' % (user.firstname + ' ' + user.name, ))
            DBSession.flush()
            print "######################"
            print "key user :", user.key

        elif user.name == gl.tmp_user_name:
            user.name = tmp_user.name
            user._set_date(datetime.datetime.now())
            user_group = DBSession.query(Group).filter(Group.name == gl.group_users).first()
            user_group.users.append(tmp_user)
            flash(u'Your account has been created %s' % (user.firstname + ' ' + user.name, ))
            DBSession.add(user)
            DBSession.flush()
            print "######################"
            print "key user :", user.key
        else:
            flash('Welcome back')
            print "######################"
            print "key user :", user.key

        #create his/her lab
        lab = DBSession.query(Labs).filter(Labs.name == tmp_lab.name).first()
        if lab is None:
            tmp_lab.users.append(user)
            DBSession.add(tmp_lab)
            DBSession.flush()
            lab = DBSession.query(Labs).filter(Labs.name == tmp_lab.name).first()
            print "lab created : ", lab
        else:
            if lab not in user.labs:
                lab.users.append(user)
                DBSession.flush()

            print "lab existing : ", lab

        #create attributs / check existing attributs
        attributs = DBSession.query(Attributs).filter(Attributs.lab_id == lab.id).all()
        if len(attributs) == 0:
            attributs = None
        lab_id = lab.id
        #parsing "unit".ini
        config = ConfigParser.RawConfigParser()
        config.read(path_conf_unit(lab.name))
        list_sample_att = (config.get('samples_attributs:main', 'keys')).split(',')
        list_sample_hiding = (config.get('samples_hiding:main', 'keys')).split(',')
        if len(list_sample_hiding) == 1 and list_sample_hiding[0] == '':
            list_sample_hiding = ''
        list_measurement_att = (config.get('meas_attributs:main', 'keys')).split(',')
        list_meas_hiding = (config.get('meas_hiding:main', 'keys')).split(',')
        if len(list_meas_hiding) == 1 and list_meas_hiding[0] == '':
            list_meas_hiding = ''
        list_searchable = (config.get('searchable_attributs:main', 'keys')).split(',')
#.........这里部分代码省略.........
开发者ID:bbcf,项目名称:biorepo,代码行数:103,代码来源:login.py


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