本文整理汇总了Python中testproject.models.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_role2
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
示例2: get_posts
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]
示例3: get_roles
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]
示例4: get_users
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]
示例5: get_permissions2
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]
示例6: delete_permissions
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
示例7: new_accesslog
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_posts
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
示例9: put_userprofile
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: delete_comment
def delete_comment(itemid):
DBSession.query(Comments).filter(Comments.id == itemid).delete()
try:
transaction.commit()
result = 1
except:
DBSession.rollback()
result = 0
return result
示例11: db_set_avatar
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
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: get_user
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
示例14: get_accesslog_badlogin
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
示例15: db_count_comments
def db_count_comments(thread, threadid):
return (
DBSession.query(Comments)
.filter(Comments.thread == thread)
.filter(Comments.published == 1)
.filter(Comments.threadid == threadid)
.count()
)