本文整理汇总了Python中kallithea.model.meta.Session.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Session.commit方法的具体用法?Python Session.commit怎么用?Python Session.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kallithea.model.meta.Session
的用法示例。
在下文中一共展示了Session.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_user_to_group
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def add_user_to_group(group, user):
ugm = UserGroupMember()
ugm.users_group = group
ugm.user = user
Session.add(ugm)
Session.commit()
return ugm
示例2: update_lastlogin
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def update_lastlogin(self):
"""Update user lastlogin"""
self.last_login = datetime.datetime.now()
Session.add(self)
Session.commit()
log.debug('updated user %s lastlogin' % self.username)
示例3: toggle_following
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def toggle_following(self):
cur_token = request.POST.get('auth_token')
token = h.get_token()
if cur_token == token:
user_id = request.POST.get('follows_user_id')
if user_id:
try:
self.scm_model.toggle_following_user(user_id,
self.authuser.user_id)
Session.commit()
return 'ok'
except Exception:
log.error(traceback.format_exc())
raise HTTPBadRequest()
repo_id = request.POST.get('follows_repo_id')
if repo_id:
try:
self.scm_model.toggle_following_repo(repo_id,
self.authuser.user_id)
Session.commit()
return 'ok'
except Exception:
log.error(traceback.format_exc())
raise HTTPBadRequest()
log.debug('token mismatch %s vs %s' % (cur_token, token))
raise HTTPBadRequest()
示例4: create_or_update_hook
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def create_or_update_hook(cls, key, val):
new_ui = cls.get_by_key(key).scalar() or cls()
new_ui.ui_section = 'hooks'
new_ui.ui_active = True
new_ui.ui_key = key
new_ui.ui_value = val
Session.add(new_ui)
Session.commit()
示例5: _set_settings
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def _set_settings(*kvtseq):
session = Session()
for kvt in kvtseq:
assert len(kvt) in (2, 3)
k = kvt[0]
v = kvt[1]
t = kvt[2] if len(kvt) == 3 else 'unicode'
Setting.create_or_update(k, v, t)
session.commit()
示例6: set_valid
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def set_valid(cls, key):
"""
Mark this cache key as active and currently cached
:param key:
"""
inv_obj = cls.get_by_key(key)
inv_obj.cache_active = True
Session.add(inv_obj)
Session.commit()
示例7: revoke_perm
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def revoke_perm(cls, users_group_id, perm):
if not isinstance(perm, Permission):
raise Exception('perm needs to be an instance of Permission class')
try:
cls.query().filter(cls.users_group_id == users_group_id) \
.filter(cls.permission == perm).delete()
Session.commit()
except:
Session.rollback()
示例8: set_valid
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def set_valid(cls, key):
"""
Mark this cache key as active and currently cached
:param key:
"""
inv_obj = Session.query(CacheInvalidation)\
.filter(CacheInvalidation.cache_key == key).scalar()
inv_obj.cache_active = True
Session.add(inv_obj)
Session.commit()
示例9: _get_or_create_key
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def _get_or_create_key(cls, key, prefix, org_key):
inv_obj = Session.query(cls).filter(cls.cache_key == key).scalar()
if not inv_obj:
try:
inv_obj = CacheInvalidation(key, org_key)
Session.add(inv_obj)
Session.commit()
except Exception:
log.error(traceback.format_exc())
Session.rollback()
return inv_obj
示例10: grant_perm
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def grant_perm(cls, users_group_id, perm):
if not isinstance(perm, Permission):
raise Exception('perm needs to be an instance of Permission class')
new = cls()
new.users_group_id = users_group_id
new.permission = perm
try:
Session.add(new)
Session.commit()
except:
Session.rollback()
示例11: create
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def create(cls, form_data):
try:
new_users_group = cls()
for k, v in form_data.items():
setattr(new_users_group, k, v)
Session.add(new_users_group)
Session.commit()
return new_users_group
except:
log.error(traceback.format_exc())
Session.rollback()
raise
示例12: set_test_settings
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def set_test_settings():
"""Restore settings after test is over."""
# Save settings.
settings_snapshot = [
(s.app_settings_name, s.app_settings_value, s.app_settings_type)
for s in Setting.query().all()]
yield _set_settings
# Restore settings.
session = Session()
keys = frozenset(k for (k, v, t) in settings_snapshot)
for s in Setting.query().all():
if s.app_settings_name not in keys:
session.delete(s)
for k, v, t in settings_snapshot:
if t == 'list' and hasattr(v, '__iter__'):
v = ','.join(v) # Quirk: must format list value manually.
Setting.create_or_update(k, v, t)
session.commit()
示例13: delete
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def delete(cls, users_group_id):
try:
# check if this group is not assigned to repo
assigned_groups = UserGroupRepoToPerm.query()\
.filter(UserGroupRepoToPerm.users_group_id ==
users_group_id).all()
if assigned_groups:
raise UserGroupsAssignedException('RepoGroup assigned to %s' %
assigned_groups)
users_group = cls.get(users_group_id, cache=False)
Session.delete(users_group)
Session.commit()
except:
log.error(traceback.format_exc())
Session.rollback()
raise
示例14: set_invalidate
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def set_invalidate(cls, key):
"""
Mark this Cache key for invalidation
:param key:
"""
key, _prefix, _org_key = cls._get_key(key)
inv_objs = Session.query(cls).filter(cls.cache_args == _org_key).all()
log.debug('marking %s key[s] %s for invalidation' % (len(inv_objs),
_org_key))
try:
for inv_obj in inv_objs:
if inv_obj:
inv_obj.cache_active = False
Session.add(inv_obj)
Session.commit()
except Exception:
log.error(traceback.format_exc())
Session.rollback()
示例15: set_invalidate
# 需要导入模块: from kallithea.model.meta import Session [as 别名]
# 或者: from kallithea.model.meta.Session import commit [as 别名]
def set_invalidate(cls, key):
"""
Mark this Cache key for invalidation
:param key:
"""
log.debug('marking %s for invalidation' % key)
inv_obj = Session.query(cls)\
.filter(cls.cache_key == key).scalar()
if inv_obj:
inv_obj.cache_active = False
else:
log.debug('cache key not found in invalidation db -> creating one')
inv_obj = CacheInvalidation(key)
try:
Session.add(inv_obj)
Session.commit()
except Exception:
log.error(traceback.format_exc())
Session.rollback()