本文整理汇总了Python中testproject.models.DBSession.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.rollback方法的具体用法?Python DBSession.rollback怎么用?Python DBSession.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testproject.models.DBSession
的用法示例。
在下文中一共展示了DBSession.rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: db_put_user
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [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
示例2: add_comment
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [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
示例3: new_user2
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [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
示例4: edit_user2
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [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
示例5: edit_post2
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [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
示例6: new_post2
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [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
示例7: new_accesslog
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [as 别名]
def new_accesslog(ip, e=1, u=0):
l = AccessLog(ip, e, user_id=u)
DBSession.add(l)
try:
transaction.commit()
except:
DBSession.rollback()
return False
示例8: delete_comment
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [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
示例9: put_userprofile
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [as 别名]
def put_userprofile(userid, post):
p = DBSession.query(Profiles).filter(Profiles.userid == userid).one()
p.fullname = post['fullname']
try:
transaction.commit()
except:
DBSession.rollback()
return False
else:
return True
示例10: new_permission2
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [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
示例11: db_set_avatar
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [as 别名]
def db_set_avatar(post):
p = DBSession.query(Profiles).filter(Profiles.userid == post['id']).all()
if not p[0]:
return False
p[0].avatar1 = post['avatarsource']
p[0].avatar2 = post['avatarsize1']
p[0].avatar3 = post['avatarsize2']
try:
transaction.commit()
except:
DBSession.rollback()
return False
else:
return True
示例12: set_userpassword
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [as 别名]
def set_userpassword(post):
setopt(Users, 'check_password', Users_check_password)
user = DBSession.query(Users).filter(Users.id == post['userid']).one()
if user.check_password(post['oldpassword']):
user.password = hash_password(post['password'])
try:
transaction.commit()
except:
DBSession.rollback()
return False
else:
return 1
else:
return 2
示例13: edit_comment
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [as 别名]
def edit_comment(itemid, title, content):
ts = int(time.time())
obj = get_comment(itemid)
obj.title = title
obj.content = content
obj.last_edited = ts
try:
transaction.commit()
result = 1
except:
DBSession.rollback()
result = 0
return result
示例14: db_get_useractivation
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [as 别名]
def db_get_useractivation(post, roles):
ua = DBSession.query(UsersActivation).filter(UsersActivation.code == post['ticket']).all()
if ua:
DBSession.query(RolesUsers).filter(RolesUsers.user_id == ua[0].userid).delete()
for e in roles:
ru = RolesUsers(ua[0].userid, e)
DBSession.add(ru)
try:
transaction.commit()
except:
DBSession.rollback()
return False
else:
return True
return ua[0]
else:
return None
示例15: db_put_comment
# 需要导入模块: from testproject.models import DBSession [as 别名]
# 或者: from testproject.models.DBSession import rollback [as 别名]
def db_put_comment(itemid, post):
p = get_bbparser()
content = p.format(post["content"])
obj = get_comment(itemid)
obj.title = post["title"]
obj.content = content
obj.last_edited = post["last_edited"]
try:
transaction.commit()
result = 1
except:
DBSession.rollback()
result = 0
return (result, content)