本文整理汇总了Python中tracim.lib.user.UserApi.get_one方法的典型用法代码示例。如果您正苦于以下问题:Python UserApi.get_one方法的具体用法?Python UserApi.get_one怎么用?Python UserApi.get_one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim.lib.user.UserApi
的用法示例。
在下文中一共展示了UserApi.get_one方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_archive
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def test_archive(self):
uapi = UserApi(None)
groups = [GroupApi(None).get_one(Group.TIM_USER),
GroupApi(None).get_one(Group.TIM_MANAGER),
GroupApi(None).get_one(Group.TIM_ADMIN)]
user = uapi.create_user(email='[email protected]',
groups=groups, save_now=True)
workspace = WorkspaceApi(user).create_workspace('test workspace',
save_now=True)
api = ContentApi(user)
item = api.create(ContentType.Folder, workspace, None,
'not_archived', True)
item2 = api.create(ContentType.Folder, workspace, None,
'to_archive', True)
uid = user.user_id
wid = workspace.workspace_id
transaction.commit()
# Refresh instances after commit
user = uapi.get_one(uid)
workspace = WorkspaceApi(user).get_one(wid)
api = ContentApi(user)
items = api.get_all(None, ContentType.Any, workspace)
eq_(2, len(items))
items = api.get_all(None, ContentType.Any, workspace)
with new_revision(items[0]):
api.archive(items[0])
transaction.commit()
# Refresh instances after commit
user = uapi.get_one(uid)
workspace = WorkspaceApi(user).get_one(wid)
api = ContentApi(user)
items = api.get_all(None, ContentType.Any, workspace)
eq_(1, len(items))
transaction.commit()
# Refresh instances after commit
user = uapi.get_one(uid)
workspace = WorkspaceApi(user).get_one(wid)
api = ContentApi(user)
# Test that the item is still available if "show deleted" is activated
api = ContentApi(None, show_archived=True)
items = api.get_all(None, ContentType.Any, workspace)
eq_(2, len(items))
示例2: test_get_all_with_filter
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def test_get_all_with_filter(self):
uapi = UserApi(None)
groups = [GroupApi(None).get_one(Group.TIM_USER),
GroupApi(None).get_one(Group.TIM_MANAGER),
GroupApi(None).get_one(Group.TIM_ADMIN)]
user = uapi.create_user(email='[email protected]',
groups=groups, save_now=True)
workspace = WorkspaceApi(user).create_workspace('test workspace',
save_now=True)
api = ContentApi(user)
item = api.create(ContentType.Folder, workspace, None,
'thefolder', True)
item2 = api.create(ContentType.File, workspace, None, 'thefile', True)
uid = user.user_id
wid = workspace.workspace_id
transaction.commit()
# Refresh instances after commit
user = uapi.get_one(uid)
workspace = WorkspaceApi(user).get_one(wid)
api = ContentApi(user)
items = api.get_all(None, ContentType.Any, workspace)
eq_(2, len(items))
items2 = api.get_all(None, ContentType.File, workspace)
eq_(1, len(items2))
eq_('thefile', items2[0].label)
items3 = api.get_all(None, ContentType.Folder, workspace)
eq_(1, len(items3))
eq_('thefolder', items3[0].label)
示例3: test_get_all_with_parent_id
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def test_get_all_with_parent_id(self):
uapi = UserApi(None)
groups = [GroupApi(None).get_one(Group.TIM_USER),
GroupApi(None).get_one(Group.TIM_MANAGER),
GroupApi(None).get_one(Group.TIM_ADMIN)]
user = uapi.create_user(email='[email protected]',
groups=groups, save_now=True)
workspace = WorkspaceApi(user).create_workspace('test workspace',
save_now=True)
api = ContentApi(user)
item = api.create(ContentType.Folder, workspace, None, 'parent', True)
item2 = api.create(ContentType.File, workspace, item, 'file1', True)
item3 = api.create(ContentType.File, workspace, None, 'file2', True)
parent_id = item.content_id
child_id = item2.content_id
uid = user.user_id
wid = workspace.workspace_id
transaction.commit()
# Refresh instances after commit
user = uapi.get_one(uid)
workspace = WorkspaceApi(user).get_one(wid)
api = ContentApi(user)
items = api.get_all(None, ContentType.Any, workspace)
eq_(3, len(items))
items2 = api.get_all(parent_id, ContentType.File, workspace)
eq_(1, len(items2))
eq_(child_id, items2[0].content_id)
示例4: edit
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def edit(self, id):
current_user = tmpl_context.current_user
api = UserApi(current_user)
user = api.get_one(id)
dictified_user = Context(CTX.USER).toDict(user, 'user')
return DictLikeClass(result = dictified_user)
示例5: put
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def put(self, user_id, name, email, next_url=''):
api = UserApi(tmpl_context.current_user)
user = api.get_one(int(user_id))
api.update(user, name, email, True)
tg.flash(_('User {} updated.').format(user.get_display_name()), CST.STATUS_OK)
if next_url:
tg.redirect(next_url)
tg.redirect(self.url())
示例6: enable
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def enable(self, id, next_url=None):
current_user = tmpl_context.current_user
api = UserApi(current_user)
user = api.get_one(id)
user.is_active = True
api.save(user)
tg.flash(_('User {} enabled.').format(user.get_display_name()), CST.STATUS_OK)
if next_url=='user':
tg.redirect(self.url(id=user.user_id))
tg.redirect(self.url())
示例7: get_one
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def get_one(self, user_id):
user_id = tmpl_context.current_user.user_id
current_user = tmpl_context.current_user
assert user_id==current_user.user_id
api = UserApi(current_user)
current_user = api.get_one(current_user.user_id)
dictified_user = Context(CTX.USER).toDict(current_user, 'user')
current_user_content = Context(CTX.CURRENT_USER).toDict(tmpl_context.current_user)
fake_api_content = DictLikeClass(current_user=current_user_content)
fake_api = Context(CTX.WORKSPACE).toDict(fake_api_content)
return DictLikeClass(result=dictified_user, fake_api=fake_api)
示例8: _add_user_with_role
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def _add_user_with_role(self, user_id: int, role_id: int, with_notif: bool, flash_msg_template)-> UserRoleInWorkspace:
user_api = UserApi(tg.tmpl_context.current_user)
user = user_api.get_one(user_id)
role_api = RoleApi(tg.tmpl_context.current_user)
role = role_api.create_one(user, tg.tmpl_context.workspace, role_id, with_notif)
tg.flash(flash_msg_template.format(
role.user.get_display_name(),
tg.tmpl_context.workspace.label,
role.role_as_label()), CST.STATUS_OK)
tg.redirect(self.parent_controller.url(tg.tmpl_context.workspace_id))
示例9: _before
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def _before(self, *args, **kw):
"""
Instantiate the current workspace in tg.tmpl_context
:param args:
:param kw:
:return:
"""
super(self.__class__, self)._before(args, kw)
api = UserApi(tg.tmpl_context.current_user)
user_id = tg.request.controller_state.routing_args.get('user_id')
user = api.get_one(user_id)
tg.tmpl_context.user_id = user_id
tg.tmpl_context.user = user
示例10: disable
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def disable(self, id, next_url=None):
id = int(id)
current_user = tmpl_context.current_user
api = UserApi(current_user)
if current_user.user_id==id:
tg.flash(_('You can\'t de-activate your own account'), CST.STATUS_ERROR)
else:
user = api.get_one(id)
user.is_active = False
api.save(user)
tg.flash(_('User {} disabled').format(user.get_display_name()), CST.STATUS_OK)
if next_url=='user':
tg.redirect(self.url(id=user.user_id))
tg.redirect(self.url())
示例11: get_one
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def get_one(self, user_id):
current_user = tmpl_context.current_user
api = UserApi(current_user )
# role_api = RoleApi(tg.tmpl_context.current_user)
# user_api = UserApi(tg.tmpl_context.current_user)
user = api.get_one(user_id) # FIXME
role_api = RoleApi(tg.tmpl_context.current_user)
role_list = role_api.get_roles_for_select_field()
dictified_user = Context(CTX.ADMIN_USER).toDict(user, 'user')
current_user_content = Context(CTX.CURRENT_USER).toDict(tmpl_context.current_user)
fake_api_content = DictLikeClass(current_user=current_user_content,
role_types=role_list)
fake_api = Context(CTX.ADMIN_USER).toDict(fake_api_content)
return DictLikeClass(result = dictified_user, fake_api=fake_api)
示例12: test_update_file_data
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def test_update_file_data(self):
uapi = UserApi(None)
groups = [GroupApi(None).get_one(Group.TIM_USER),
GroupApi(None).get_one(Group.TIM_MANAGER),
GroupApi(None).get_one(Group.TIM_ADMIN)]
user1 = uapi.create_user(email='[email protected]',
groups=groups, save_now=True)
workspace = WorkspaceApi(user1).create_workspace('test workspace',
save_now=True)
wid = workspace.workspace_id
user2 = uapi.create_user()
user2.email = '[email protected]'
uapi.save(user2)
RoleApi(user1).create_one(user2, workspace,
UserRoleInWorkspace.CONTENT_MANAGER,
with_notif=True,
flush=True)
# Test starts here
api = ContentApi(user1)
p = api.create(ContentType.File, workspace, None,
'this_is_a_page', True)
u1id = user1.user_id
u2id = user2.user_id
pcid = p.content_id
poid = p.owner_id
api.save(p)
transaction.commit()
# Refresh instances after commit
user1 = uapi.get_one(u1id)
workspace = WorkspaceApi(user1).get_one(wid)
api = ContentApi(user1)
content = api.get_one(pcid, ContentType.Any, workspace)
eq_(u1id, content.owner_id)
eq_(poid, content.owner_id)
u2 = UserApi(None).get_one(u2id)
api2 = ContentApi(u2)
content2 = api2.get_one(pcid, ContentType.Any, workspace)
with new_revision(content2):
api2.update_file_data(content2, 'index.html', 'text/html',
b'<html>hello world</html>')
api2.save(content2)
transaction.commit()
# Refresh instances after commit
user1 = uapi.get_one(u1id)
workspace = WorkspaceApi(user1).get_one(wid)
updated = api.get_one(pcid, ContentType.Any, workspace)
eq_(u2id, updated.owner_id,
'the owner id should be {} (found {})'.format(u2id,
updated.owner_id))
eq_('this_is_a_page.html', updated.file_name)
eq_('text/html', updated.file_mimetype)
eq_(b'<html>hello world</html>', updated.file_content)
eq_(ActionDescription.REVISION, updated.revision_type)
示例13: test_update
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def test_update(self):
uapi = UserApi(None)
groups = [GroupApi(None).get_one(Group.TIM_USER),
GroupApi(None).get_one(Group.TIM_MANAGER),
GroupApi(None).get_one(Group.TIM_ADMIN)]
user1 = uapi.create_user(email='[email protected]',
groups=groups, save_now=True)
workspace = WorkspaceApi(user1).create_workspace('test workspace',
save_now=True)
wid = workspace.workspace_id
user2 = uapi.create_user()
user2.email = '[email protected]'
uapi.save(user2)
RoleApi(user1).create_one(user2, workspace,
UserRoleInWorkspace.CONTENT_MANAGER,
with_notif=False,
flush=True)
# Test starts here
api = ContentApi(user1)
p = api.create(ContentType.Page, workspace, None,
'this_is_a_page', True)
u1id = user1.user_id
u2id = user2.user_id
pcid = p.content_id
poid = p.owner_id
transaction.commit()
# Refresh instances after commit
user1 = uapi.get_one(u1id)
workspace = WorkspaceApi(user1).get_one(wid)
api = ContentApi(user1)
content = api.get_one(pcid, ContentType.Any, workspace)
eq_(u1id, content.owner_id)
eq_(poid, content.owner_id)
u2 = UserApi(None).get_one(u2id)
api2 = ContentApi(u2)
content2 = api2.get_one(pcid, ContentType.Any, workspace)
with new_revision(content2):
api2.update_content(content2, 'this is an updated page', 'new content')
api2.save(content2)
transaction.commit()
# Refresh instances after commit
user1 = uapi.get_one(u1id)
workspace = WorkspaceApi(user1).get_one(wid)
api = ContentApi(user1)
updated = api.get_one(pcid, ContentType.Any, workspace)
eq_(u2id, updated.owner_id,
'the owner id should be {} (found {})'.format(u2id,
updated.owner_id))
eq_('this is an updated page', updated.label)
eq_('new content', updated.description)
eq_(ActionDescription.EDITION, updated.revision_type)
示例14: test_get_one
# 需要导入模块: from tracim.lib.user import UserApi [as 别名]
# 或者: from tracim.lib.user.UserApi import get_one [as 别名]
def test_get_one(self):
api = UserApi(None)
u = api.create_user()
api.update(u, 'titi', '[email protected]', True)
one = api.get_one(u.user_id)
eq_(u.user_id, one.user_id)