• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python model.DBSession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: delete_user

 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,代码行数:7,代码来源:sequence.py


示例2: delete_track

 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,代码行数:7,代码来源:sequence.py


示例3: change_rights

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,代码行数:28,代码来源:project.py


示例4: edit

    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,代码行数:60,代码来源:project.py


示例5: add_read_right

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,代码行数:7,代码来源:project.py


示例6: admin

    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,代码行数:32,代码来源:track.py


示例7: add_read_right_to_circles_ids

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,代码行数:8,代码来源:project.py


示例8: delete

 def delete(self, _id):
     user = handler.user.get_user_in_session(request)
     if not checker.can_edit_job(user.id, _id):
         return {'error': "You have don't have the right to delete this job"}
     job = DBSession.query(Job).filter(Job.id == _id).first()
     # TODO delete results (DB + filesystem)
     DBSession.delete(job)
     raise redirect('/jobs')
开发者ID:bbcf,项目名称:pygdv,代码行数:8,代码来源:job.py


示例9: edit

    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,代码行数:58,代码来源:sequence.py


示例10: get_permissions

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,代码行数:9,代码来源:permission.py


示例11: delete

 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,代码行数:9,代码来源:circle.py


示例12: add_tracks

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,代码行数:9,代码来源:project.py


示例13: add_right

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,代码行数:10,代码来源:project.py


示例14: delete_user

 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,代码行数:10,代码来源:circle.py


示例15: create_tmp_user

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,代码行数:10,代码来源:user.py


示例16: after_process

 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,代码行数:10,代码来源:track.py


示例17: user_own_circle

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,代码行数:12,代码来源:checker.py


示例18: delete

 def delete(self, project_id, selection_id):
     user = handler.user.get_user_in_session(request)
     if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id):
         flash('You must have %s permission to delete the project.' % constants.right_upload, 'error')
         return {'delete': 'failed'}
     selection = DBSession.query(Selection).filter(Selection.id == selection_id).first()
     if not selection.project_id == project_id:
         flash('Bad project_id: %s' % project_id, 'error')
         return {'delete': 'failed'}
     DBSession.delete(selection)
     DBSession.flush()
     return {'delete': 'success'}
开发者ID:bbcf,项目名称:pygdv,代码行数:12,代码来源:selection.py


示例19: edit

def edit(track=None, track_id=None, name=None, color=None):
    if track is None:
        track = DBSession.query(Track).filter(Track.id == track_id).first()
    debug('edit track %s' % track)
    if name is not None:
        track.name = name
    if track.parameters is None:
        init(track)
    if color is not None:
        p = copy.deepcopy(track.parameters)
        p.update({'color': color})
        track.parameters = p
    DBSession.flush()
开发者ID:bbcf,项目名称:pygdv,代码行数:13,代码来源:track.py


示例20: link

 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,代码行数:13,代码来源:track.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.FileClass类代码示例发布时间:2022-05-25
下一篇:
Python parser.source_reader_t函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap