當前位置: 首頁>>代碼示例>>Python>>正文


Python DBSession.flush方法代碼示例

本文整理匯總了Python中pygdv.model.DBSession.flush方法的典型用法代碼示例。如果您正苦於以下問題:Python DBSession.flush方法的具體用法?Python DBSession.flush怎麽用?Python DBSession.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pygdv.model.DBSession的用法示例。


在下文中一共展示了DBSession.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_read_right

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
def add_read_right(project, circle_id):    
    '''
    Add the ``read`` right to the project & circle specified. Flush the database
    '''
    _add_read_right(project, circle_id)
    DBSession.add(project)
    DBSession.flush()
開發者ID:bbcf,項目名稱:pygdv,代碼行數:9,代碼來源:project.py

示例2: add_new_sequence

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
def add_new_sequence(sequence):
    '''
    Method called when a new sequence is created on GDV.
    It should import fast from JBrowse
    '''
    print 'add new sequence'
    file_url = Assembly(sequence).get_sqlite_url()
    print file_url
    out = os.path.join(filemanager.temporary_directory(), 'Genes.sql')
    fileinfo = filemanager.FileInfo(inputtype='url',
        inpath=file_url, trackname='Genes', extension='sql', outpath=out, admin=True)
    print fileinfo
    user = DBSession.query(User).filter(User.key == constants.admin_user_key()).first()
    user_info = {'id': user.id, 'name': user.name, 'email': user.email}
    sequence_info = {'id': sequence.id, 'name': sequence.name}

    # track
    t = Track()
    t.name = fileinfo.trackname
    t.sequence_id = sequence.id
    t.user_id = user.id
    DBSession.add(t)
    DBSession.flush()
    # send task
    async = tasks.new_input.delay(user_info, fileinfo, sequence_info, t.id)
    t.task_id = async.task_id
    DBSession.add(t)

    sequence.default_tracks.append(t)
    DBSession.add(sequence)
    DBSession.flush()
開發者ID:bbcf,項目名稱:pygdv,代碼行數:33,代碼來源:sequence.py

示例3: delete_user

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
 def delete_user(self, user_id, sequence_id):
     user = handler.user.get_user_in_session(request)
     s = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first()
     u = DBSession.query(User).filter(User.id == user_id).first()
     s.users.remove(u)
     DBSession.flush()
     raise redirect('/sequences/edit/%s' % sequence_id)
開發者ID:bbcf,項目名稱:pygdv,代碼行數:9,代碼來源:sequence.py

示例4: after_sha1

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
    def after_sha1(self, fname, sha1, force, callback_url, track_id, old_task_id, mail, key, sequence_id, extension, trackname):
        """
        Called after a sha1 where calculated on a file.
        If the sha1 already exist, only the databases operations are done.
        Else the input will go in the second part of the process.
        The input can be 'forced' to be recomputed
        """
        try:
            _input = DBSession.query(Input).filter(Input.sha1 == sha1).first()
            do_process = True
            if util.str2bool(force) and _input is not None:
                handler.track.delete_input(_input.sha1)
                DBSession.delete(_input)
                DBSession.flush()
            elif _input is not None:
                do_process = False
                handler.track.update(track_id=track_id,
                    params={'new_input_id': _input.id})
                handler.track.finalize_track_creation(track_id=track_id)

            if do_process:

                handler.track.update(track_id=track_id, params={'sha1': sha1})
                sequence = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first()
                async = tasks.track_process.delay(mail, key, old_task_id, fname, sha1, callback_url, track_id, sequence.name, extension, trackname, callback_url)

                handler.track.update(track_id=track_id,
                    params={'new_task_id': async.task_id})
            return {'success': 'to second process'}
        except Exception as e:
            etype, value, tb = sys.exc_info()
            traceback.print_exception(etype, value, tb)


            return {'error': str(e)}
開發者ID:bbcf,項目名稱:pygdv,代碼行數:37,代碼來源:track.py

示例5: edit

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
def edit(project, name, user_id, sequence_id=None, tracks=None, isPublic=False, circles=None):
    '''
    Like create but edit an existing project.
    '''
    project.name=name
    if sequence_id is not None:
        project.sequence_id = sequence_id
    project.user_id = user_id
    project.is_public = isPublic
    DBSession.add(project)
    DBSession.flush()

    project.tracks = []
    if tracks is not None:
        for track_id in tracks :
            t = DBSession.query(Track).filter(Track.id == track_id).first()
            project.tracks.append(t)
    
   
    if circles is not None: # adding circle with the read permission by default
        project._circle_right = []
        for circle in circles : _add_read_right(project, circle.id)
    
    DBSession.add(project)
    DBSession.flush()
    return project
開發者ID:bbcf,項目名稱:pygdv,代碼行數:28,代碼來源:project.py

示例6: validation

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
 def validation(*args, **kw):
     for arg in args_list:
         if arg not in kw:
             raise Exception('Missing args for the validation %s' % kw)
     user = DBSession.query(User).filter(User.email == str(kw['mail'])).first()
     if user.key != str(kw['key']):
         raise Exception('User not valid %s' % kw)
     project = DBSession.query(Project).filter(Project.id == int(kw['pid'])).first()
     if project.key != str(kw['pkey']):
         raise Exception('Project not valid %s' % kw)
     job = Job()
     job.user_id = user.id
     job.project_id = project.id
     job.status = 'PENDING'
     job.ext_task_id = kw['task_id']
     job.bioscript_url = handler.job.task_url(kw['task_id'])
     if 'plugin_info' in kw:
         info = json.loads(kw['plugin_info'])
         job.name = info['title']
         job.description = info['description']
     else:
         job.name = 'Job %s from bioscript' % kw['task_id']
         job.description = 'Description available at %s' % handler.job.task_url(kw['task_id'])
     DBSession.add(job)
     DBSession.flush()
     return {}
開發者ID:bbcf,項目名稱:pygdv,代碼行數:28,代碼來源:plugin.py

示例7: delete_track

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
 def delete_track(self, sequence_id, track_id):
     user = handler.user.get_user_in_session(request)
     s = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first()
     t = DBSession.query(Track).filter(Track.id == track_id).first()
     s.default_tracks.remove(t)
     DBSession.flush()
     raise redirect('/sequences/edit/%s' % sequence_id)
開發者ID:bbcf,項目名稱:pygdv,代碼行數:9,代碼來源:sequence.py

示例8: change_rights

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
def change_rights(project_id, circle_id, rights=None):
    '''
    Modify the right associated to a project to a group.
    If any right is added, automatically add read right.
    @param project_id : the project id
    @param circle_id : the circle id
    @param rights : the right to update
    '''
    project = DBSession.query(Project).filter(Project.id == project_id).first()
    rc_assocs = get_circle_right_assocs(circle_id, project_id)
    
    
    for rc in rc_assocs:
        if rc.circle.id == int(circle_id) :
            project._circle_right.remove(rc)
            DBSession.delete(rc)
            DBSession.flush()

    if rights is not None:
        _add_read_right(project, circle_id)
        for right_name in rights:
            if right_name != constants.right_read :
                right = DBSession.query(Right).filter(Right.name == right_name).first()
                cr_assoc = _get_circle_right_assoc(right, circle_id, project_id)
                project._circle_right.append(cr_assoc)

    DBSession.add(project)
    DBSession.flush()
開發者ID:bbcf,項目名稱:pygdv,代碼行數:30,代碼來源:project.py

示例9: add_read_right_to_circles_ids

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
def add_read_right_to_circles_ids(project, ids):
    '''
     Add the ``read`` right to the project & circles specified. Flush the database
    '''  
    for id in ids:
        _add_read_right(project, id)
    DBSession.add(project)
    DBSession.flush()
開發者ID:bbcf,項目名稱:pygdv,代碼行數:10,代碼來源:project.py

示例10: edit

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
    def edit(self, *args, **kw):
        user = handler.user.get_user_in_session(request)

        # get circle id
        if request.method == 'GET':
            sequence_id = args[0]
        else :
            sequence_id = kw.get('cid')

        sequence_id=int(sequence_id)
        sequence = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first()
        if not sequence:
            abort(404, 'Sequence with id %s not found' % sequence_id)

        if not sequence.public:
            add_user_widget = form.AddUser(action=url('/sequences/edit/%s' % sequence_id)).req()

            if request.method == 'POST':
                # add an user
                mail = kw.get('mail')
                try:
                    add_user_widget.validate({'cid' : sequence_id, 'mail' : mail})
                except twc.ValidationError as e:
                    users = ', '.join(['%s' % u.email for u in sequence.users])
                    default_tracks = ', '.join(['%s' % t.name for t in sequence.default_tracks])
                    kw['cid'] = sequence_id
                    users = sequence.users
                    for u in users:
                        u.__dict__['sid'] = sequence_id
                    widget = e.widget
                    widget.value = kw
                    return dict(page='sequences', users=users, add_user=add_user, add_user_widget=add_user_widget, default_tracks=default_tracks, au_error=True, seq_id=sequence_id)

                to_add = DBSession.query(User).filter(User.email == mail).first()
                if to_add is None:
                    to_add = handler.user.create_tmp_user(mail)
                sequence.users.append(to_add)
                DBSession.flush()

            kw['cid'] = sequence_id
            add_user_widget.value = kw

        else:
            add_user_widget = None

        users = sequence.users
        for u in users:
            u.__dict__['sid'] = sequence_id

        tracks = sequence.default_tracks
        for t in tracks:
            t.__dict__['sid'] = sequence_id

        add_user = util.to_datagrid(datagrid.sequence_user_grid, users, "Users", len(users)>0)

        def_tracks = util.to_datagrid(datagrid.sequence_default_tracks, tracks, "Default tracks", len(tracks)>0)

        return dict(page='sequences', users=users, add_user=add_user, add_user_widget=add_user_widget, default_tracks=def_tracks, au_error=False, seq_id=sequence_id)
開發者ID:bbcf,項目名稱:pygdv,代碼行數:60,代碼來源:sequence.py

示例11: add_tracks

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
def add_tracks(project, track_ids):
    '''
    Add a list of track to the project specified.
    '''
    for track_id in track_ids:
        track_ = DBSession.query(Track).filter(Track.id == track_id).first()
        project.tracks.append(track_)
    DBSession.add(project)
    DBSession.flush()
開發者ID:bbcf,項目名稱:pygdv,代碼行數:11,代碼來源:project.py

示例12: delete

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
 def delete(self, circle_id, *args, **kw):
     user = handler.user.get_user_in_session(request)
     if not checker.user_own_circle(user.id, circle_id):
         flash('you have no right to delete this circle: you are not the creator of it')
         raise redirect('/circles')
     circle = DBSession.query(Circle).filter(Circle.id == circle_id).first()
     DBSession.delete(circle)
     DBSession.flush()
     raise redirect('/circles/')
開發者ID:bbcf,項目名稱:pygdv,代碼行數:11,代碼來源:circle.py

示例13: after_process

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
 def after_process(self, mail, key, old_task_id, track_id, datatype):
     print '[x] after process [x] %s' % track_id
     task = DBSession.query(Task).filter(Task.task_id == old_task_id).first()
     if task is not None:
         DBSession.delete(task)
         DBSession.flush()
     if not track_id == 'None':
         handler.track.update(track_id=track_id, params={'datatype': datatype})
         handler.track.finalize_track_creation(track_id=track_id)
     return {'success': 'end'}
開發者ID:bbcf,項目名稱:pygdv,代碼行數:12,代碼來源:track.py

示例14: delete_user

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
 def delete_user(self, id, user_id):
     user = handler.user.get_user_in_session(request)
     if not checker.user_own_circle(user.id, id):
         flash('you have no rights to delete users from this circle: you are not the creator of it')
         raise redirect('/circles')
     circle = DBSession.query(Circle).filter(Circle.id == id).first()
     to_delete = DBSession.query(User).filter(User.id == user_id).first()
     circle.users.remove(to_delete)
     DBSession.flush()
     raise redirect('/circles/edit/%s' % id)
開發者ID:bbcf,項目名稱:pygdv,代碼行數:12,代碼來源:circle.py

示例15: create_tmp_user

# 需要導入模塊: from pygdv.model import DBSession [as 別名]
# 或者: from pygdv.model.DBSession import flush [as 別名]
def create_tmp_user(mail):
    user = User()
    user.name = constants.tmp_user_name
    user.email = mail
    user.firstname = ''
    user_group = DBSession.query(Group).filter(Group.id == constants.group_users_id).first()
    user_group.users.append(user)
    DBSession.add(user)
    DBSession.flush()
    return user
開發者ID:bbcf,項目名稱:pygdv,代碼行數:12,代碼來源:user.py


注:本文中的pygdv.model.DBSession.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。