本文整理汇总了Python中kallithea.model.db.UserGroup.get_or_404方法的典型用法代码示例。如果您正苦于以下问题:Python UserGroup.get_or_404方法的具体用法?Python UserGroup.get_or_404怎么用?Python UserGroup.get_or_404使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kallithea.model.db.UserGroup
的用法示例。
在下文中一共展示了UserGroup.get_or_404方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_members
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def edit_members(self, id):
c.user_group = UserGroup.get_or_404(id)
c.active = 'members'
c.group_members_obj = sorted((x.user for x in c.user_group.members),
key=lambda u: u.username.lower())
c.group_members = [(x.user_id, x.username) for x in c.group_members_obj]
return render('admin/user_groups/user_group_edit.html')
示例2: __load_defaults
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def __load_defaults(self, user_group_id):
"""
Load defaults settings for edit, and update
:param user_group_id:
"""
user_group = UserGroup.get_or_404(user_group_id)
data = user_group.get_dict()
return data
示例3: delete
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def delete(self, id):
usr_gr = UserGroup.get_or_404(id)
try:
UserGroupModel().delete(usr_gr)
Session().commit()
h.flash(_('Successfully deleted user group'), category='success')
except UserGroupsAssignedException as e:
h.flash(e, category='error')
except Exception:
log.error(traceback.format_exc())
h.flash(_('An error occurred during deletion of user group'),
category='error')
raise HTTPFound(location=url('users_groups'))
示例4: edit
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def edit(self, id, format='html'):
c.user_group = UserGroup.get_or_404(id)
c.active = 'settings'
self.__load_data(id)
defaults = self.__load_defaults(id)
return htmlfill.render(
render('admin/user_groups/user_group_edit.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=False
)
示例5: delete
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def delete(self, id):
"""DELETE /user_groups/id: Delete an existing item"""
# Forms posted to this method should contain a hidden field:
# <input type="hidden" name="_method" value="DELETE" />
# Or using helpers:
# h.form(url('users_group', id=ID),
# method='delete')
# url('users_group', id=ID)
usr_gr = UserGroup.get_or_404(id)
try:
UserGroupModel().delete(usr_gr)
Session().commit()
h.flash(_('Successfully deleted user group'), category='success')
except UserGroupsAssignedException, e:
h.flash(e, category='error')
示例6: edit
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def edit(self, id, format='html'):
"""GET /user_groups/id/edit: Form to edit an existing item"""
# url('edit_users_group', id=ID)
c.user_group = UserGroup.get_or_404(id)
c.active = 'settings'
self.__load_data(id)
defaults = self.__load_defaults(id)
return htmlfill.render(
render('admin/user_groups/user_group_edit.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=False
)
示例7: edit_default_perms
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def edit_default_perms(self, id):
c.user_group = UserGroup.get_or_404(id)
c.active = 'default_perms'
permissions = {
'repositories': {},
'repositories_groups': {}
}
ugroup_repo_perms = UserGroupRepoToPerm.query() \
.options(joinedload(UserGroupRepoToPerm.permission)) \
.options(joinedload(UserGroupRepoToPerm.repository)) \
.filter(UserGroupRepoToPerm.users_group_id == id) \
.all()
for gr in ugroup_repo_perms:
permissions['repositories'][gr.repository.repo_name] \
= gr.permission.permission_name
ugroup_group_perms = UserGroupRepoGroupToPerm.query() \
.options(joinedload(UserGroupRepoGroupToPerm.permission)) \
.options(joinedload(UserGroupRepoGroupToPerm.group)) \
.filter(UserGroupRepoGroupToPerm.users_group_id == id) \
.all()
for gr in ugroup_group_perms:
permissions['repositories_groups'][gr.group.group_name] \
= gr.permission.permission_name
c.permissions = permissions
ug_model = UserGroupModel()
defaults = c.user_group.get_dict()
defaults.update({
'create_repo_perm': ug_model.has_perm(c.user_group,
'hg.create.repository'),
'create_user_group_perm': ug_model.has_perm(c.user_group,
'hg.usergroup.create.true'),
'fork_repo_perm': ug_model.has_perm(c.user_group,
'hg.fork.repository'),
})
return htmlfill.render(
render('admin/user_groups/user_group_edit.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=False
)
示例8: update
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def update(self, id):
"""PUT /user_groups/id: Update an existing item"""
# Forms posted to this method should contain a hidden field:
# <input type="hidden" name="_method" value="PUT" />
# Or using helpers:
# h.form(url('users_group', id=ID),
# method='put')
# url('users_group', id=ID)
c.user_group = UserGroup.get_or_404(id)
c.active = 'settings'
self.__load_data(id)
available_members = [safe_unicode(x[0]) for x in c.available_members]
users_group_form = UserGroupForm(edit=True,
old_data=c.user_group.get_dict(),
available_members=available_members)()
try:
form_result = users_group_form.to_python(request.POST)
UserGroupModel().update(c.user_group, form_result)
gr = form_result['users_group_name']
action_logger(self.authuser,
'admin_updated_users_group:%s' % gr,
None, self.ip_addr, self.sa)
h.flash(_('Updated user group %s') % gr, category='success')
Session().commit()
except formencode.Invalid, errors:
ug_model = UserGroupModel()
defaults = errors.value
e = errors.error_dict or {}
defaults.update({
'create_repo_perm': ug_model.has_perm(id,
'hg.create.repository'),
'fork_repo_perm': ug_model.has_perm(id,
'hg.fork.repository'),
'_method': 'put'
})
return htmlfill.render(
render('admin/user_groups/user_group_edit.html'),
defaults=defaults,
errors=e,
prefix_error=False,
encoding="UTF-8",
force_defaults=False)
示例9: update
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def update(self, id):
c.user_group = UserGroup.get_or_404(id)
c.active = 'settings'
self.__load_data(id)
available_members = [safe_unicode(x[0]) for x in c.available_members]
users_group_form = UserGroupForm(edit=True,
old_data=c.user_group.get_dict(),
available_members=available_members)()
try:
form_result = users_group_form.to_python(request.POST)
UserGroupModel().update(c.user_group, form_result)
gr = form_result['users_group_name']
action_logger(request.authuser,
'admin_updated_users_group:%s' % gr,
None, request.ip_addr)
h.flash(_('Updated user group %s') % gr, category='success')
Session().commit()
except formencode.Invalid as errors:
ug_model = UserGroupModel()
defaults = errors.value
e = errors.error_dict or {}
defaults.update({
'create_repo_perm': ug_model.has_perm(id,
'hg.create.repository'),
'fork_repo_perm': ug_model.has_perm(id,
'hg.fork.repository'),
})
return htmlfill.render(
render('admin/user_groups/user_group_edit.html'),
defaults=defaults,
errors=e,
prefix_error=False,
encoding="UTF-8",
force_defaults=False)
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during update of user group %s') \
% request.POST.get('users_group_name'), category='error')
raise HTTPFound(location=url('edit_users_group', id=id))
示例10: update_default_perms
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def update_default_perms(self, id):
"""PUT /users_perm/id: Update an existing item"""
# url('users_group_perm', id=ID, method='put')
user_group = UserGroup.get_or_404(id)
try:
form = CustomDefaultPermissionsForm()()
form_result = form.to_python(request.POST)
inherit_perms = form_result['inherit_default_permissions']
user_group.inherit_default_permissions = inherit_perms
Session().add(user_group)
usergroup_model = UserGroupModel()
defs = UserGroupToPerm.query()\
.filter(UserGroupToPerm.users_group == user_group)\
.all()
for ug in defs:
Session().delete(ug)
if form_result['create_repo_perm']:
usergroup_model.grant_perm(id, 'hg.create.repository')
else:
usergroup_model.grant_perm(id, 'hg.create.none')
if form_result['create_user_group_perm']:
usergroup_model.grant_perm(id, 'hg.usergroup.create.true')
else:
usergroup_model.grant_perm(id, 'hg.usergroup.create.false')
if form_result['fork_repo_perm']:
usergroup_model.grant_perm(id, 'hg.fork.repository')
else:
usergroup_model.grant_perm(id, 'hg.fork.none')
h.flash(_("Updated permissions"), category='success')
Session().commit()
except Exception:
log.error(traceback.format_exc())
h.flash(_('An error occurred during permissions saving'),
category='error')
return redirect(url('edit_user_group_default_perms', id=id))
示例11: update_perms
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def update_perms(self, id):
"""
grant permission for given usergroup
:param id:
"""
user_group = UserGroup.get_or_404(id)
form = UserGroupPermsForm()().to_python(request.POST)
# set the permissions !
try:
UserGroupModel()._update_permissions(user_group, form['perms_new'],
form['perms_updates'])
except RepoGroupAssignmentError:
h.flash(_('Target group cannot be the same'), category='error')
raise HTTPFound(location=url('edit_user_group_perms', id=id))
#TODO: implement this
#action_logger(request.authuser, 'admin_changed_repo_permissions',
# repo_name, request.ip_addr)
Session().commit()
h.flash(_('User group permissions updated'), category='success')
raise HTTPFound(location=url('edit_user_group_perms', id=id))
示例12: edit_perms
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import get_or_404 [as 别名]
def edit_perms(self, id):
c.user_group = UserGroup.get_or_404(id)
c.active = 'perms'
repo_model = RepoModel()
c.users_array = repo_model.get_users_js()
c.user_groups_array = repo_model.get_user_groups_js()
defaults = {}
# fill user group users
for p in c.user_group.user_user_group_to_perm:
defaults.update({'u_perm_%s' % p.user.username:
p.permission.permission_name})
for p in c.user_group.user_group_user_group_to_perm:
defaults.update({'g_perm_%s' % p.user_group.users_group_name:
p.permission.permission_name})
return htmlfill.render(
render('admin/user_groups/user_group_edit.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=False
)