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


Python DBSession.query方法代码示例

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


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

示例1: admin

# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import query [as 别名]
    def admin(self, **kw):
        # view on a specific project
        grid = datagrid.track_admin_grid
        if kw.has_key('pid'):
            project_id = kw.get('pid')
            project = DBSession.query(Project).filter(Project.id == project_id).first()
            tracks = project.tracks
            kw['upload'] = True

            kw['pn'] = project.name
            track_list = [util.to_datagrid(grid, tracks, "Track Listing", len(tracks)>0)]

        else:
            if 'user_id' in kw:
                tracks = DBSession.query(Track).filter(Track.user_id == kw['user_id']).all()
            else:
                tracks = DBSession.query(Track).all()
            track_list = [util.to_datagrid(grid, tracks, "Track Listing", len(tracks)>0)]
            kw['upload'] = True

        # track list

        t = handler.help.tooltip['admin']

        # project list
        all_projects = DBSession.query(Project).all()
        project_list = [(p.id, p.name,) for p in all_projects]


        return dict(page='tracks', model='track', form_title="new track", track_list=track_list,
            project_list=project_list, shared_project_list=[], value=kw,
            tooltip=t, project_id=kw.get('pid', None), upload=kw.get('upload', None), project_name=kw.get('pn', None))
开发者ID:bbcf,项目名称:pygdv,代码行数:34,代码来源:track.py

示例2: e

# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import query [as 别名]
def e(project=None, project_id=None, name=None, track_ids=None, circle_ids=None):
    if project is None:
        project = DBSession.query(Project).filter(Project.id == project_id).first()

    if name is not None:
        project.name = name

    if track_ids is not None:
        project.tracks = []
        for tid in track_ids:
            t = DBSession.query(Track).filter(Track.id == tid).first()
            project.tracks.append(t)

    if circle_ids is not None:
        if not isinstance(circle_ids, list):
            circle_ids = [circle_ids]
        circle_ids = [int(i) for i in circle_ids]
        to_del = []
        for shared in project._circle_right:
            if shared.circle.id not in circle_ids:
                to_del.append(shared)
        for d in to_del:
            DBSession.delete(d)
            project._circle_right.remove(d)
        DBSession.flush()

        shared_ids = [c.id for c in project.shared_circles]
        read_right = DBSession.query(Right).filter(Right.id == constants.rights['read']['id']).first()
        for new_id in circle_ids:
            if new_id not in shared_ids:
                add_right(project=project, circle_id=new_id, right=read_right)
        DBSession.flush()
    DBSession.add(project)
    DBSession.flush()
    return project
开发者ID:bbcf,项目名称:pygdv,代码行数:37,代码来源:project.py

示例3: delete_track

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

示例4: edit

# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import query [as 别名]
    def edit(self, *args, **kw):
        user = handler.user.get_user_in_session(request)
        if request.method == 'GET':
            project_id = args[0]
        else:
            project_id = kw.get('pid')
        debug("check permission", 1)
        if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id) and not checker.is_admin(user=user):
            flash('You must have %s permission to edit the project.' % constants.right_upload, 'error')
            raise redirect('/tracks/', {'pid': project_id})
        #if checker.is_admin(user=user):
            #user = DBSession.query(User).join(Project).filter(Project.id == project_id).first()

        widget = form.EditProject(action=url('/projects/edit/%s' % project_id)).req()
        widget.value = {'pid': project_id}
        project = DBSession.query(Project).filter(Project.id == project_id).first()

        # prendre les user tracks du meme sequence id
        tracks = DBSession.query(Track).join(User.tracks).filter(
            and_(User.id == user.id, Track.sequence_id == project.sequence_id,
                not_(Track.id.in_([t.id for t in project.tracks])))
        ).all()

        # prendre les sared tracks du meme sequence id
        shared_tracks = handler.user.shared_tracks(user.id, constants.rights['download']['id'])
        shared_tracks = [t for t in shared_tracks if (t.sequence_id == project.sequence_id and t.id not in [tr.id for tr in project.tracks])]

        tracks.extend(shared_tracks)

        if request.method == 'GET':
            debug("GET", 2)
            widget.child.children[1].value = project.name
            widget.child.children[2].options = [('', '')] + [(t.id, t.name) for t in tracks] + [(t.id, t.name, {'selected': True}) for t in project.tracks]
            return dict(page='tracks', widget=widget, project_id=project_id)
        debug("POST", 2)
        try:
            debug("validate post", 2)
            widget.validate(kw)
        except twc.ValidationError as e:
            debug("error", 2)
            w = e.widget
            w.child.children[1].value = project.name
            w.child.children[2].options = [(t.id, t.name) for t in tracks] + [(t.id, t.name, {'selected': True}) for t in project.tracks]
            return dict(page='tracks', widget=w, project_id=project_id)
        debug("validation passed")
        track_ids = kw.get('tracks', [])
        if not track_ids:
            track_ids = []
        if not isinstance(track_ids, list):
            track_ids = [track_ids]
        if len(track_ids) > 0 and '' in track_ids:
            track_ids.remove('')

        # if the project is shared, some track cannot be removed
        for t in project.tracks:
            if not checker.user_own_track(user.id, track=t) and t.id not in track_ids and t.id in [s.id for s in shared_tracks]:
                track_ids.append(t.id)

        handler.project.e(project_id=project_id, name=kw.get('name'), track_ids=track_ids)
        raise redirect('/tracks/', {'pid': project_id})
开发者ID:bbcf,项目名称:pygdv,代码行数:62,代码来源:project.py

示例5: delete_user

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

示例6: change_rights

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

示例7: validation

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

示例8: after_sha1

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

示例9: edit

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

示例10: get_permissions

# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import query [as 别名]
def get_permissions(admin):
    '''
    Get the right permissions for an user.
    @param admin : True if the user is an admin.
    @type admin : a boolean.
    '''
    if admin :
        return DBSession.query(Permission).all()
    return DBSession.query(Permission).filter(Permission.name != 'admin').all()
开发者ID:bbcf,项目名称:pygdv,代码行数:11,代码来源:permission.py

示例11: delete_user

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

示例12: add_right

# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import query [as 别名]
def add_right(project=None, project_id=None, circle=None, circle_id=None, right=None, right_id=None):
    if project is None:
        project = DBSession.query(Project).filter(Project.id == project_id).first()
    if circle_id is None:
        circle_id = circle.id
    if right is None:
        right = DBSession.query(Right).filter(Right.id == right_id).first()

    cr_assoc = _get_circle_right_assoc(right, circle_id, project.id)
    project._circle_right.append(cr_assoc)
开发者ID:bbcf,项目名称:pygdv,代码行数:12,代码来源:project.py

示例13: user_own_circle

# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import query [as 别名]
def user_own_circle(user_id, circle_id):
    '''
    Look if the user own the circle.
    '''
    circle = DBSession.query(Circle).filter(Circle.id == circle_id).first()
    if circle.creator_id == user_id:
        return True
    if circle.admin:
        user = DBSession.query(User).filter(User.id == user_id).first()
        admin_group = DBSession.query(Group).filter(Group.name == constants.group_admins).first()
        return user in admin_group.users
    return False
开发者ID:bbcf,项目名称:pygdv,代码行数:14,代码来源:checker.py

示例14: link

# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import query [as 别名]
 def link(self, track_id, *args, **kw):
     user = handler.user.get_user_in_session(request)
     trac = DBSession.query(Track).filter(Track.id == track_id).first()
     if not checker.can_download(user, trac):
         flash("You haven't the right to download any tracks which is not yours", 'error')
         raise redirect('/tracks/')
     track = DBSession.query(Track).filter(Track.id == track_id).first()
     if track.status == constants.ERROR:
         flash("The track processing failed. You cannot download it.", 'error')
         raise redirect('/tracks/')
     response.content_type = 'application/x-sqlite3'
     response.headerlist.append(('Content-Disposition', 'attachment;filename=%s.sqlite' % track.name))
     return open(track.path).read()
开发者ID:bbcf,项目名称:pygdv,代码行数:15,代码来源:track.py

示例15: get_rights

# 需要导入模块: from pygdv.model import DBSession [as 别名]
# 或者: from pygdv.model.DBSession import query [as 别名]
def get_rights(project=None, project_id=None, user=None, user_id=None):
    if project is None:
        project = DBSession.query(Project).filter(Project.id == project_id).first()
    if user is None:
        user = DBSession.query(User).filter(User.id == user_id).first()

    debug('get rights %s' % project.get_circle_with_right_display)
    r = []
    for circle, rights in project.circles_with_rights.iteritems():
        debug('circle %s with rights %s' % (circle, rights), 1)

        if circle in user.circles:
            r.extend(rights)
    return r
开发者ID:bbcf,项目名称:pygdv,代码行数:16,代码来源:project.py


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