本文整理汇总了Python中kallithea.model.db.UserGroup.query方法的典型用法代码示例。如果您正苦于以下问题:Python UserGroup.query方法的具体用法?Python UserGroup.query怎么用?Python UserGroup.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kallithea.model.db.UserGroup
的用法示例。
在下文中一共展示了UserGroup.query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enforce_groups
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import query [as 别名]
def test_enforce_groups(self, pre_existing, regular_should_be,
external_should_be, groups, expected):
# delete all groups
for gr in UserGroup.query():
fixture.destroy_user_group(gr)
Session().commit()
user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
for gr in pre_existing:
gr = fixture.create_user_group(gr)
Session().commit()
# make sure use is just in those groups
for gr in regular_should_be:
gr = fixture.create_user_group(gr)
Session().commit()
UserGroupModel().add_user_to_group(gr, user)
Session().commit()
# now special external groups created by auth plugins
for gr in external_should_be:
gr = fixture.create_user_group(gr, user_group_data={'extern_type': 'container'})
Session().commit()
UserGroupModel().add_user_to_group(gr, user)
Session().commit()
UserGroupModel().enforce_groups(user, groups, 'container')
Session().commit()
user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
in_groups = user.group_member
assert expected == [x.users_group.users_group_name for x in in_groups]
示例2: get_user_groups_js
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import query [as 别名]
def get_user_groups_js(self):
user_groups = UserGroup.query() \
.filter(UserGroup.users_group_active == True) \
.order_by(UserGroup.users_group_name) \
.options(subqueryload(UserGroup.members)) \
.all()
user_groups = UserGroupList(user_groups, perm_level='read')
return [
{
'id': gr.users_group_id,
'grname': gr.users_group_name,
'grmembers': len(gr.members),
} for gr in user_groups]
示例3: index
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import query [as 别名]
def index(self, format='html'):
"""GET /users_groups: All items in the collection"""
# url('users_groups')
_list = UserGroup.query()\
.order_by(func.lower(UserGroup.users_group_name))\
.all()
group_iter = UserGroupList(_list, perm_set=['usergroup.admin'])
user_groups_data = []
total_records = len(group_iter)
_tmpl_lookup = kallithea.CONFIG['pylons.app_globals'].mako_lookup
template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
user_group_name = lambda user_group_id, user_group_name: (
template.get_def("user_group_name")
.render(user_group_id, user_group_name, _=_, h=h, c=c)
)
user_group_actions = lambda user_group_id, user_group_name: (
template.get_def("user_group_actions")
.render(user_group_id, user_group_name, _=_, h=h, c=c)
)
for user_gr in group_iter:
user_groups_data.append({
"raw_name": user_gr.users_group_name,
"group_name": user_group_name(user_gr.users_group_id,
user_gr.users_group_name),
"desc": user_gr.user_group_description,
"members": len(user_gr.members),
"active": h.boolicon(user_gr.users_group_active),
"owner": h.person(user_gr.user.username),
"action": user_group_actions(user_gr.users_group_id, user_gr.users_group_name)
})
c.data = json.dumps({
"totalRecords": total_records,
"startIndex": 0,
"sort": None,
"dir": "asc",
"records": user_groups_data
})
return render('admin/user_groups/user_groups.html')
示例4: index
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import query [as 别名]
def index(self, format='html'):
_list = UserGroup.query() \
.order_by(func.lower(UserGroup.users_group_name)) \
.all()
group_iter = UserGroupList(_list, perm_level='admin')
user_groups_data = []
total_records = len(group_iter)
_tmpl_lookup = app_globals.mako_lookup
template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
user_group_name = lambda user_group_id, user_group_name: (
template.get_def("user_group_name")
.render(user_group_id, user_group_name, _=_, h=h, c=c)
)
user_group_actions = lambda user_group_id, user_group_name: (
template.get_def("user_group_actions")
.render(user_group_id, user_group_name, _=_, h=h, c=c)
)
for user_gr in group_iter:
user_groups_data.append({
"raw_name": user_gr.users_group_name,
"group_name": user_group_name(user_gr.users_group_id,
user_gr.users_group_name),
"desc": h.escape(user_gr.user_group_description),
"members": len(user_gr.members),
"active": h.boolicon(user_gr.users_group_active),
"owner": h.person(user_gr.owner.username),
"action": user_group_actions(user_gr.users_group_id, user_gr.users_group_name)
})
c.data = {
"totalRecords": total_records,
"startIndex": 0,
"sort": None,
"dir": "asc",
"records": user_groups_data
}
return render('admin/user_groups/user_groups.html')
示例5: to_python
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import query [as 别名]
def to_python(self, value, state):
perms_update = OrderedSet()
perms_new = OrderedSet()
# build a list of permission to update and new permission to create
#CLEAN OUT ORG VALUE FROM NEW MEMBERS, and group them using
new_perms_group = defaultdict(dict)
for k, v in value.copy().iteritems():
if k.startswith('perm_new_member'):
del value[k]
_type, part = k.split('perm_new_member_')
args = part.split('_')
if len(args) == 1:
new_perms_group[args[0]]['perm'] = v
elif len(args) == 2:
_key, pos = args
new_perms_group[pos][_key] = v
# fill new permissions in order of how they were added
for k in sorted(map(int, new_perms_group.keys())):
perm_dict = new_perms_group[str(k)]
new_member = perm_dict.get('name')
new_perm = perm_dict.get('perm')
new_type = perm_dict.get('type')
if new_member and new_perm and new_type:
perms_new.add((new_member, new_perm, new_type))
for k, v in value.iteritems():
if k.startswith('u_perm_') or k.startswith('g_perm_'):
member = k[7:]
t = {'u': 'user',
'g': 'users_group'
}[k[0]]
if member == User.DEFAULT_USER:
if str2bool(value.get('repo_private')):
# set none for default when updating to
# private repo protects against form manipulation
v = EMPTY_PERM
perms_update.add((member, v, t))
value['perms_updates'] = list(perms_update)
value['perms_new'] = list(perms_new)
# update permissions
for k, v, t in perms_new:
try:
if t is 'user':
self.user_db = User.query() \
.filter(User.active == True) \
.filter(User.username == k).one()
if t is 'users_group':
self.user_db = UserGroup.query() \
.filter(UserGroup.users_group_active == True) \
.filter(UserGroup.users_group_name == k).one()
except Exception:
log.exception('Updated permission failed')
msg = M(self, 'perm_new_member_type', state)
raise formencode.Invalid(msg, value, state,
error_dict=dict(perm_new_member_name=msg)
)
return value
示例6: teardown_method
# 需要导入模块: from kallithea.model.db import UserGroup [as 别名]
# 或者: from kallithea.model.db.UserGroup import query [as 别名]
def teardown_method(self, method):
# delete all groups
for gr in UserGroup.query():
fixture.destroy_user_group(gr)
Session().commit()