本文整理汇总了Python中tracim.lib.user.UserApi类的典型用法代码示例。如果您正苦于以下问题:Python UserApi类的具体用法?Python UserApi怎么用?Python UserApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserApi类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: put
def put(self, user_id, name, email, timezone, next_url=None):
user_id = tmpl_context.current_user.user_id
current_user = tmpl_context.current_user
user_api = UserApi(current_user)
assert user_id==current_user.user_id
if next_url:
next = tg.url(next_url)
else:
next = self.url()
try:
email_user = user_api.get_one_by_email(email)
if email_user != current_user:
tg.flash(_('Email already in use'), CST.STATUS_ERROR)
tg.redirect(next)
except NoResultFound:
pass
# Only keep allowed field update
updated_fields = self._clean_update_fields({
'name': name,
'email': email,
'timezone': timezone,
})
api = UserApi(tmpl_context.current_user)
api.update(current_user, do_save=True, **updated_fields)
tg.flash(_('profile updated.'))
tg.redirect(next)
开发者ID:lebouquetin,项目名称:tracim,代码行数:29,代码来源:user.py
示例2: test_mark_read
def test_mark_read(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_a = uapi.create_user(email='[email protected]',
groups=groups, save_now=True)
user_b = uapi.create_user(email='[email protected]',
groups=groups, save_now=True)
wapi = WorkspaceApi(user_a)
workspace = wapi.create_workspace(
'test workspace',
save_now=True)
role_api = RoleApi(user_a)
role_api.create_one(user_b, workspace, UserRoleInWorkspace.READER, False)
cont_api_a = ContentApi(user_a)
cont_api_b = ContentApi(user_b)
page_1 = cont_api_a.create(ContentType.Page, workspace, None,
'this is a page', do_save=True)
for rev in page_1.revisions:
eq_(user_b not in rev.read_by.keys(), True)
cont_api_b.mark_read(page_1)
for rev in page_1.revisions:
eq_(user_b in rev.read_by.keys(), True)
开发者ID:lebouquetin,项目名称:tracim,代码行数:30,代码来源:test_content_api.py
示例3: test_get_all_with_filter
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)
开发者ID:buxx,项目名称:tracim,代码行数:34,代码来源:test_content_api.py
示例4: test_search_in_description
def test_search_in_description(self):
# HACK - D.A. - 2015-03-09
# This test is based on a bug which does NOT return results found
# at root of a workspace (eg a folder)
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)
a = api.create(ContentType.Folder, workspace, None,
'this is randomized folder', True)
p = api.create(ContentType.Page, workspace, a,
'this is dummy label content', True)
with new_revision(p):
p.description = 'This is some amazing test'
api.save(p)
original_id = p.content_id
res = api.search(['dummy'])
eq_(1, len(res.all()))
item = res.all()[0]
eq_(original_id, item.content_id)
开发者ID:buxx,项目名称:tracim,代码行数:32,代码来源:test_content_api.py
示例5: test_unit__get_all_manageable
def test_unit__get_all_manageable(self):
admin = DBSession.query(User) \
.filter(User.email == '[email protected]').one()
uapi = UserApi(admin)
# Checks a case without workspaces.
wapi = WorkspaceApi(current_user=admin)
eq_([], wapi.get_all_manageable())
# Checks an admin gets all workspaces.
w4 = wapi.create_workspace(label='w4')
w3 = wapi.create_workspace(label='w3')
w2 = wapi.create_workspace(label='w2')
w1 = wapi.create_workspace(label='w1')
eq_([w1, w2, w3, w4], wapi.get_all_manageable())
# Checks a regular user gets none workspace.
gapi = GroupApi(None)
u = uapi.create_user('[email protected]', [gapi.get_one(Group.TIM_USER)], True)
wapi = WorkspaceApi(current_user=u)
rapi = RoleApi(current_user=u)
rapi.create_one(u, w4, UserRoleInWorkspace.READER, False)
rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, False)
rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, False)
rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, False)
eq_([], wapi.get_all_manageable())
# Checks a manager gets only its own workspaces.
u.groups.append(gapi.get_one(Group.TIM_MANAGER))
rapi.delete_one(u.user_id, w2.workspace_id)
rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, False)
eq_([w1, w2], wapi.get_all_manageable())
开发者ID:lebouquetin,项目名称:tracim,代码行数:28,代码来源:test_workspace.py
示例6: test_get_all_with_parent_id
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)
开发者ID:Nonolost,项目名称:tracim,代码行数:32,代码来源:test_content_api.py
示例7: insert
def insert(self):
u = model.User()
u.display_name = 'Global manager'
u.email = '[email protected]'
u.password = '[email protected]'
self._session.add(u)
uapi = UserApi(u)
uapi.execute_created_user_actions(u)
g1 = model.Group()
g1.group_id = 1
g1.group_name = 'users'
g1.display_name = 'Users'
g1.users.append(u)
self._session.add(g1)
g2 = model.Group()
g2.group_id = 2
g2.group_name = 'managers'
g2.display_name = 'Global Managers'
g2.users.append(u)
self._session.add(g2)
g3 = model.Group()
g3.group_id = 3
g3.group_name = 'administrators'
g3.display_name = 'Administrators'
g3.users.append(u)
self._session.add(g3)
开发者ID:lebouquetin,项目名称:tracim,代码行数:29,代码来源:users_and_groups.py
示例8: edit
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)
开发者ID:Nonolost,项目名称:tracim,代码行数:8,代码来源:user.py
示例9: test_get_one_by_email
def test_get_one_by_email(self):
api = UserApi(None)
u = api.create_user()
api.update(u, 'bibi', '[email protected]', True)
uid = u.user_id
transaction.commit()
eq_(uid, api.get_one_by_email('[email protected]').user_id)
开发者ID:DarkDare,项目名称:tracim,代码行数:8,代码来源:test_user_api.py
示例10: test_create_and_update_user
def test_create_and_update_user(self):
api = UserApi(None)
u = api.create_user()
api.update(u, 'bob', '[email protected]', True)
nu = api.get_one_by_email('[email protected]')
ok_(nu!=None)
eq_('[email protected]', nu.email)
eq_('bob', nu.display_name)
开发者ID:DarkDare,项目名称:tracim,代码行数:9,代码来源:test_user_api.py
示例11: put
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())
开发者ID:Nonolost,项目名称:tracim,代码行数:10,代码来源:user.py
示例12: put
def put(self, user_id, name, email, next_url=None):
user_id = tmpl_context.current_user.user_id
current_user = tmpl_context.current_user
assert user_id==current_user.user_id
api = UserApi(tmpl_context.current_user)
api.update(current_user, name, email, True)
tg.flash(_('profile updated.'))
if next_url:
tg.redirect(tg.url(next_url))
tg.redirect(self.url())
开发者ID:DarkDare,项目名称:tracim,代码行数:11,代码来源:user.py
示例13: get_all
def get_all(self, *args, **kw):
current_user = tmpl_context.current_user
api = UserApi(current_user)
users = api.get_all()
current_user_content = Context(CTX.CURRENT_USER).toDict(current_user)
fake_api = Context(CTX.USERS).toDict({'current_user': current_user_content})
dictified_users = Context(CTX.USERS).toDict(users, 'users', 'user_nb')
return DictLikeClass(result = dictified_users, fake_api=fake_api)
开发者ID:Nonolost,项目名称:tracim,代码行数:11,代码来源:user.py
示例14: enable
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())
开发者ID:Nonolost,项目名称:tracim,代码行数:12,代码来源:user.py
示例15: test_get_notifiable_roles
def test_get_notifiable_roles(self):
admin = DBSession.query(User) \
.filter(User.email == '[email protected]').one()
wapi = WorkspaceApi(admin)
w = wapi.create_workspace(label='workspace w', save_now=True)
uapi = UserApi(admin)
u = uapi.create_user(email='[email protected]', save_now=True)
eq_([], wapi.get_notifiable_roles(workspace=w))
rapi = RoleApi(u)
r = rapi.create_one(u, w, UserRoleInWorkspace.READER, with_notif=True)
eq_([r, ], wapi.get_notifiable_roles(workspace=w))
u.is_active = False
eq_([], wapi.get_notifiable_roles(workspace=w))
开发者ID:lebouquetin,项目名称:tracim,代码行数:13,代码来源:test_workspace.py
示例16: _add_user_with_role
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))
开发者ID:Nonolost,项目名称:tracim,代码行数:13,代码来源:workspace.py
示例17: get_one
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)
开发者ID:DarkDare,项目名称:tracim,代码行数:13,代码来源:user.py
示例18: test_archive
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))
开发者ID:buxx,项目名称:tracim,代码行数:51,代码来源:test_content_api.py
示例19: test_set_status_unknown_status
def test_set_status_unknown_status(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)
c = api.create(ContentType.Folder, workspace, None, 'parent', True)
api.set_status(c, 'unknown-status')
开发者ID:DarkDare,项目名称:tracim,代码行数:14,代码来源:test_content_api.py
示例20: _before
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
开发者ID:Nonolost,项目名称:tracim,代码行数:14,代码来源:user.py
注:本文中的tracim.lib.user.UserApi类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论