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


Python DBSession.flush方法代码示例

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


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

示例1: add_comment

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import flush [as 别名]
def add_comment(userid, thread, threadid, threadtitle, title, content):

    p = Parser()
    p.add_simple_formatter(
        "video",
        '<object width="480" height="360"><embed src="http://www.youtube.com/v/%(value)s" type="application/x-shockwave-flash" width="480" height="360"></embed></object>',
    )
    p.add_simple_formatter(
        "img", '<img style="max-width:480px; max-height:400px;" src="%(value)s" alt="" />', replace_links=False
    )

    ts = int(time.time())

    DBSession.autoflush = False
    c = Comments(userid, thread, threadid, threadtitle, title, p.format(content), created=ts)
    DBSession.add(c)
    DBSession.flush()

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

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

示例2: db_put_user

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

示例3: new_user2

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import flush [as 别名]
def new_user2(post, roles, useavatars):

    ts = time.time()

    # Добавляем запись
    DBSession.autoflush = False

    if useavatars == 1 and "avatarsource" in post:
        # Если используем аваторы
        addprofiles = Profiles(post["fullname"], post["avatarsource"], post["avatarsize1"], post["avatarsize2"])
    else:
        # Если нет
        addprofiles = Profiles(post["fullname"])

    u = Users(post["username"], post["email"], hash_password(post["password"]), ts, 1, addprofiles)

    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 u
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:35,代码来源:users_func.py

示例4: new_post2

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import flush [as 别名]
def new_post2(post, tags):
    
    ts = time.time()
    
    #Добавляем запись
    DBSession.autoflush = False
    
    p = Blogs(post['title'], post['alias'], post['userid'], post['into'], post['content'],
              post['published'], post['comments'], post['comments_premoderation'], ts)
    
    DBSession.add(p)
    DBSession.flush()
    DBSession.refresh(p)
    
    #Добавляем тэги
    for e in tags:
        pt = TagsPosts(p.id, e)
        DBSession.add(pt)
        DBSession.flush()
        
    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return p
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:29,代码来源:posts_func.py

示例5: new_permission2

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import flush [as 别名]
def new_permission2(post):
    #Добавляем запись
    DBSession.autoflush = False
    r = Permissions(post['permname'], description=post['description'], ordering=post['order'])   
    DBSession.add(r)
    DBSession.flush()
    DBSession.refresh(r)
            
    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return r
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:17,代码来源:permissions_func.py

示例6: new_role2

# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import flush [as 别名]
def new_role2(post, permissions):
    #Добавляем запись
    DBSession.autoflush = False
    r = Roles(post['rolename'], post['rolegroup'], description=post['description'], ordering=post['order'])   
    DBSession.add(r)
    DBSession.flush()
    DBSession.refresh(r)
    
    #Добавляем права
    for e in permissions:
        pr = PermissionsRoles(r.id, e)
        DBSession.add(pr)
        DBSession.flush()
            
    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return r
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:23,代码来源:roles_func.py

示例7: db_add_comment

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

    p = get_bbparser()

    content = p.format(post["content"])

    DBSession.autoflush = False
    c = Comments(
        post["userid"], post["thread"], post["threadid"], post["threadtitle"], post["title"], content, post["created"]
    )
    DBSession.add(c)
    DBSession.flush()
    DBSession.refresh(c)

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

    u = DBSession.query(Users).filter(Users.id == post["userid"]).one()

    return (result, content, c.id, u.profiles.avatar3)
开发者ID:lightarhont,项目名称:startwithpyramid,代码行数:26,代码来源:comments_func.py


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