本文整理汇总了Python中kallithea.model.db.RepoGroup.guess_instance方法的典型用法代码示例。如果您正苦于以下问题:Python RepoGroup.guess_instance方法的具体用法?Python RepoGroup.guess_instance怎么用?Python RepoGroup.guess_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kallithea.model.db.RepoGroup
的用法示例。
在下文中一共展示了RepoGroup.guess_instance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_perms
# 需要导入模块: from kallithea.model.db import RepoGroup [as 别名]
# 或者: from kallithea.model.db.RepoGroup import guess_instance [as 别名]
def update_perms(self, group_name):
"""
Update permissions for given repository group
:param group_name:
"""
c.repo_group = RepoGroup.guess_instance(group_name)
valid_recursive_choices = ['none', 'repos', 'groups', 'all']
form_result = RepoGroupPermsForm(valid_recursive_choices)().to_python(request.POST)
if not request.authuser.is_admin:
if self._revoke_perms_on_yourself(form_result):
msg = _('Cannot revoke permission for yourself as admin')
h.flash(msg, category='warning')
raise HTTPFound(location=url('edit_repo_group_perms', group_name=group_name))
recursive = form_result['recursive']
# iterate over all members(if in recursive mode) of this groups and
# set the permissions !
# this can be potentially heavy operation
RepoGroupModel()._update_permissions(c.repo_group,
form_result['perms_new'],
form_result['perms_updates'],
recursive)
#TODO: implement this
#action_logger(request.authuser, 'admin_changed_repo_permissions',
# repo_name, request.ip_addr)
Session().commit()
h.flash(_('Repository group permissions updated'), category='success')
raise HTTPFound(location=url('edit_repo_group_perms', group_name=group_name))
示例2: delete
# 需要导入模块: from kallithea.model.db import RepoGroup [as 别名]
# 或者: from kallithea.model.db.RepoGroup import guess_instance [as 别名]
def delete(self, group_name):
gr = c.repo_group = RepoGroup.guess_instance(group_name)
repos = gr.repositories.all()
if repos:
h.flash(_('This group contains %s repositories and cannot be '
'deleted') % len(repos), category='warning')
raise HTTPFound(location=url('repos_groups'))
children = gr.children.all()
if children:
h.flash(_('This group contains %s subgroups and cannot be deleted'
% (len(children))), category='warning')
raise HTTPFound(location=url('repos_groups'))
try:
RepoGroupModel().delete(group_name)
Session().commit()
h.flash(_('Removed repository group %s') % group_name,
category='success')
#TODO: in future action_logger(, '', '', '')
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during deletion of repository group %s')
% group_name, category='error')
if gr.parent_group:
raise HTTPFound(location=url('repos_group_home', group_name=gr.parent_group.group_name))
raise HTTPFound(location=url('repos_groups'))
示例3: edit_repo_group_perms
# 需要导入模块: from kallithea.model.db import RepoGroup [as 别名]
# 或者: from kallithea.model.db.RepoGroup import guess_instance [as 别名]
def edit_repo_group_perms(self, group_name):
c.active = 'perms'
c.repo_group = RepoGroup.guess_instance(group_name)
self.__load_defaults()
defaults = self.__load_data(c.repo_group.group_id)
return htmlfill.render(
render('admin/repo_groups/repo_group_edit.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=False
)
示例4: edit
# 需要导入模块: from kallithea.model.db import RepoGroup [as 别名]
# 或者: from kallithea.model.db.RepoGroup import guess_instance [as 别名]
def edit(self, group_name):
c.active = 'settings'
c.repo_group = RepoGroup.guess_instance(group_name)
self.__load_defaults(extras=[c.repo_group.parent_group],
exclude=[c.repo_group])
defaults = self.__load_data(c.repo_group.group_id)
return htmlfill.render(
render('admin/repo_groups/repo_group_edit.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=False
)
示例5: show
# 需要导入模块: from kallithea.model.db import RepoGroup [as 别名]
# 或者: from kallithea.model.db.RepoGroup import guess_instance [as 别名]
def show(self, group_name):
c.active = 'settings'
c.group = c.repo_group = RepoGroup.guess_instance(group_name)
groups = RepoGroup.query(sorted=True).filter_by(parent_group=c.group).all()
c.groups = self.scm_model.get_repo_groups(groups)
repos_list = Repository.query(sorted=True).filter_by(group=c.group).all()
repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list,
admin=False, short_name=True)
# data used to render the grid
c.data = repos_data
return render('admin/repo_groups/repo_group_show.html')
示例6: update
# 需要导入模块: from kallithea.model.db import RepoGroup [as 别名]
# 或者: from kallithea.model.db.RepoGroup import guess_instance [as 别名]
def update(self, group_name):
c.repo_group = RepoGroup.guess_instance(group_name)
self.__load_defaults(extras=[c.repo_group.parent_group],
exclude=[c.repo_group])
# TODO: kill allow_empty_group - it is only used for redundant form validation!
if HasPermissionAny('hg.admin')('group edit'):
#we're global admin, we're ok and we can create TOP level groups
allow_empty_group = True
elif not c.repo_group.parent_group:
allow_empty_group = True
else:
allow_empty_group = False
repo_group_form = RepoGroupForm(
edit=True,
old_data=c.repo_group.get_dict(),
repo_groups=c.repo_groups,
can_create_in_root=allow_empty_group,
)()
try:
form_result = repo_group_form.to_python(dict(request.POST))
new_gr = RepoGroupModel().update(group_name, form_result)
Session().commit()
h.flash(_('Updated repository group %s') \
% form_result['group_name'], category='success')
# we now have new name !
group_name = new_gr.group_name
#TODO: in future action_logger(, '', '', '')
except formencode.Invalid as errors:
c.active = 'settings'
return htmlfill.render(
render('admin/repo_groups/repo_group_edit.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8",
force_defaults=False)
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during update of repository group %s') \
% request.POST.get('group_name'), category='error')
raise HTTPFound(location=url('edit_repo_group', group_name=group_name))
示例7: edit_repo_group_advanced
# 需要导入模块: from kallithea.model.db import RepoGroup [as 别名]
# 或者: from kallithea.model.db.RepoGroup import guess_instance [as 别名]
def edit_repo_group_advanced(self, group_name):
c.active = 'advanced'
c.repo_group = RepoGroup.guess_instance(group_name)
return render('admin/repo_groups/repo_group_edit.html')
示例8: _create_repo
# 需要导入模块: from kallithea.model.db import RepoGroup [as 别名]
# 或者: from kallithea.model.db.RepoGroup import guess_instance [as 别名]
def _create_repo(self, repo_name, repo_type, description, owner,
private=False, clone_uri=None, repo_group=None,
landing_rev='rev:tip', fork_of=None,
copy_fork_permissions=False, enable_statistics=False,
enable_locking=False, enable_downloads=False,
copy_group_permissions=False, state=Repository.STATE_PENDING):
"""
Create repository inside database with PENDING state. This should only be
executed by create() repo, with exception of importing existing repos.
"""
from kallithea.model.scm import ScmModel
owner = User.guess_instance(owner)
fork_of = Repository.guess_instance(fork_of)
repo_group = RepoGroup.guess_instance(repo_group)
try:
repo_name = safe_unicode(repo_name)
description = safe_unicode(description)
# repo name is just a name of repository
# while repo_name_full is a full qualified name that is combined
# with name and path of group
repo_name_full = repo_name
repo_name = repo_name.split(self.URL_SEPARATOR)[-1]
new_repo = Repository()
new_repo.repo_state = state
new_repo.enable_statistics = False
new_repo.repo_name = repo_name_full
new_repo.repo_type = repo_type
new_repo.owner = owner
new_repo.group = repo_group
new_repo.description = description or repo_name
new_repo.private = private
new_repo.clone_uri = clone_uri
new_repo.landing_rev = landing_rev
new_repo.enable_statistics = enable_statistics
new_repo.enable_locking = enable_locking
new_repo.enable_downloads = enable_downloads
if repo_group:
new_repo.enable_locking = repo_group.enable_locking
if fork_of:
parent_repo = fork_of
new_repo.fork = parent_repo
Session().add(new_repo)
if fork_of and copy_fork_permissions:
repo = fork_of
user_perms = UserRepoToPerm.query() \
.filter(UserRepoToPerm.repository == repo).all()
group_perms = UserGroupRepoToPerm.query() \
.filter(UserGroupRepoToPerm.repository == repo).all()
for perm in user_perms:
UserRepoToPerm.create(perm.user, new_repo, perm.permission)
for perm in group_perms:
UserGroupRepoToPerm.create(perm.users_group, new_repo,
perm.permission)
elif repo_group and copy_group_permissions:
user_perms = UserRepoGroupToPerm.query() \
.filter(UserRepoGroupToPerm.group == repo_group).all()
group_perms = UserGroupRepoGroupToPerm.query() \
.filter(UserGroupRepoGroupToPerm.group == repo_group).all()
for perm in user_perms:
perm_name = perm.permission.permission_name.replace('group.', 'repository.')
perm_obj = Permission.get_by_key(perm_name)
UserRepoToPerm.create(perm.user, new_repo, perm_obj)
for perm in group_perms:
perm_name = perm.permission.permission_name.replace('group.', 'repository.')
perm_obj = Permission.get_by_key(perm_name)
UserGroupRepoToPerm.create(perm.users_group, new_repo, perm_obj)
else:
self._create_default_perms(new_repo, private)
# now automatically start following this repository as owner
ScmModel().toggle_following_repo(new_repo.repo_id, owner.user_id)
# we need to flush here, in order to check if database won't
# throw any exceptions, create filesystem dirs at the very end
Session().flush()
return new_repo
except Exception:
log.error(traceback.format_exc())
raise