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


Python DBSession.query方法代码示例

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


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

示例1: edit_user2

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def edit_user2(post, roles, useavatars):
    # Обновлеяем запись
    obj = get_user2(post["id"])
    if not obj:
        return False
    obj.username = post["username"]
    obj.email = post["email"]
    obj.profiles.fullname = post["fullname"]
    if useavatars == 1 and "avatarsource" in post:
        obj.profiles.avatar1 = post["avatarsource"]
        obj.profiles.avatar2 = post["avatarsize1"]
        obj.profiles.avatar3 = post["avatarsize2"]
    if post["password"] != "":
        obj.password = hash_password(post["password"])

    # Удаляем роли
    DBSession.query(RolesUsers).filter(RolesUsers.user_id == post["id"]).delete()

    # Добавляем роли
    for e in roles:
        ru = RolesUsers(post["id"], e)
        DBSession.add(ru)

    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return True
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:32,代码来源:users_func.py

示例2: edit_post2

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def edit_post2(post, tags):
    
    ts = time.time()
    
    obj = get_post2(post['id'])
    if not obj:
        return False
    obj.title = post['title']
    obj.slug = post['alias']
    obj.userid = post['userid']
    obj.intro = post['into']
    obj.content = post['content']
    obj.published = post['published']
    obj.comments = post['comments']
    obj.comments_premoderation = post['comments_premoderation']
    obj.last_edited = ts
    
    #Удаляем тэги
    DBSession.query(TagsPosts).filter(TagsPosts.post_id == post['id']).delete()
    
    #Добавляем тэги
    for e in tags:
        pt = TagsPosts(post['id'], e)
        DBSession.add(pt)
    
    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return True
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:34,代码来源:posts_func.py

示例3: edit_role2

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def edit_role2(post, permissions):
    #Обновлеяем запись
    obj = get_role2(post['id'])
    if not obj:
        return False
    obj.name = post['rolename']
    obj.rolesgroup = post['rolegroup']
    obj.description = post['description']
    obj.ordering = post['order']  
    
    #Удаляем роли
    DBSession.query(PermissionsRoles).filter(PermissionsRoles.role_id == post['id']).delete()
            
    #Добавляем роли
    for e in permissions:
        pr = PermissionsRoles(post['id'], e)
        DBSession.add(pr)  
    
    try:
        transaction.commit()
    except:
        transaction.rollback()
        return False
    else:
        return True
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:27,代码来源:roles_func.py

示例4: get_posts

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def get_posts(offset=None, limit=None):
    
    setallroute()
    
    if offset==None or limit==None:
        return DBSession.query(Blogs).all()
    else:
        return (DBSession.query(Blogs).all())[offset:limit]
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:10,代码来源:posts_func.py

示例5: get_roles

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def get_roles(offset=None, limit=None):
    
    #Добавить короткое описание
    setopt(Roles, 'shortdesc', Roles_shortdesc)
    
    if offset==None or limit==None:
        return DBSession.query(Roles).all()
    else:
        return DBSession.query(Roles).all()[offset:limit]
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:11,代码来源:roles_func.py

示例6: get_permissions2

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def get_permissions2(offset=None, limit=None):
    
    #Добавить короткое описание
    setopt(Permissions, 'shortdesc', Permissions_shortdesc)
    
    if offset==None or limit==None:
        return DBSession.query(Permissions).all()
    else:
        return DBSession.query(Permissions).all()[offset:limit]
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:11,代码来源:permissions_func.py

示例7: get_users

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def get_users(offset=None, limit=None):

    # Форматирование даты и активности
    setallroute()

    if offset == None or limit == None:
        return DBSession.query(Users).all()
    else:
        return (DBSession.query(Users).all())[offset:limit]
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:11,代码来源:users_func.py

示例8: delete_permissions

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def delete_permissions(delitems):
    try:
        for e in delitems:
            DBSession.query(Permissions).filter(Permissions.id == e).delete()
        transaction.commit()
        result = 1
    except:
        transaction.rollback()
        result = 0
    return result
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:12,代码来源:permissions_func.py

示例9: delete_posts

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def delete_posts(delitems, thread='blog'):
    try:
        for e in delitems:
            DBSession.query(Blogs).filter(Blogs.id == e).delete()
            DBSession.query(Comments).filter(Comments.thread == thread).filter(Comments.threadid == e).delete()
        transaction.commit()
        result = 1
    except:
        transaction.rollback()
        result = 0
    return result
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:13,代码来源:posts_func.py

示例10: delete_comment

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def delete_comment(itemid):

    DBSession.query(Comments).filter(Comments.id == itemid).delete()

    try:
        transaction.commit()
        result = 1
    except:
        DBSession.rollback()
        result = 0

    return result
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:14,代码来源:comments_func.py

示例11: get_accesslog_badlogin

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def get_accesslog_badlogin(ip, e=1, t=180, attempt=3):
    
    ls = DBSession.query(AccessLog).filter(AccessLog.event_id == e).filter(AccessLog.ip == ip).filter(AccessLog.eventdate > int(time.time())-180).count()
    if ls < attempt:
        return True
    else:
        return False
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:9,代码来源:auth_func.py

示例12: get_user

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def get_user(username):
    setopt(Users, 'check_password', Users_check_password)
    user = DBSession.query(Users).filter(Users.username == username).all()
    if user:
        return user[0]
    else:
        return None
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:9,代码来源:auth_func.py

示例13: db_put_user

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def db_put_user(post, roles, token):
    user = DBSession.query(Users).filter(or_(Users.username == post['username'], Users.email == post['email'])).all()
    if not user:
        ts = time.time()
        DBSession.autoflush = False
        addprofiles = Profiles(post['fullname'], '', '', '')
        usersactivation = UsersActivation(token, ts)
        u = Users(post['username'], post['email'], hash_password(post['password']), ts, 1, addprofiles, usersactivation=usersactivation)
    
        DBSession.add(u)
        DBSession.flush()
        DBSession.refresh(u)
    
        for e in roles:
            ru = RolesUsers(u.id, e)
            DBSession.add(ru)
            DBSession.flush()
    
        try:
            transaction.commit()
        except:
            DBSession.rollback()
            return False
        else:
            return True
    else:
        return 3
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:29,代码来源:user_func.py

示例14: count_comments

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def count_comments(component, componentid):
    return (
        DBSession.query(Comments)
        .filter(Comments.thread == component)
        .filter(Comments.threadid == componentid)
        .filter(Comments.published == 1)
        .count()
    )
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:10,代码来源:comments_func.py

示例15: db_count_comments

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import query [as 别名]
def db_count_comments(thread, threadid):
    return (
        DBSession.query(Comments)
        .filter(Comments.thread == thread)
        .filter(Comments.published == 1)
        .filter(Comments.threadid == threadid)
        .count()
    )
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:10,代码来源:comments_func.py


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