本文整理汇总了Python中tracim.lib.content.ContentApi.undelete方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.undelete方法的具体用法?Python ContentApi.undelete怎么用?Python ContentApi.undelete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim.lib.content.ContentApi
的用法示例。
在下文中一共展示了ContentApi.undelete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put_delete_undo
# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import undelete [as 别名]
def put_delete_undo(self, item_id):
require_current_user_is_owner(int(item_id))
item_id = int(item_id)
content_api = ContentApi(tmpl_context.current_user, True, True) # Here we do not filter deleted items
item = content_api.get_one(item_id, self._item_type, tmpl_context.workspace)
try:
next_url = tg.url('/workspaces/{}/folders/{}/threads/{}').format(tmpl_context.workspace_id,
tmpl_context.folder_id,
tmpl_context.thread_id)
msg = _('{} undeleted.').format(self._item_type_label)
content_api.undelete(item)
content_api.save(item, ActionDescription.UNDELETION)
tg.flash(msg, CST.STATUS_OK)
tg.redirect(next_url)
except ValueError as e:
logger.debug(self, 'Exception: {}'.format(e.__str__))
back_url = tg.url('/workspaces/{}/folders/{}/threads/{}').format(tmpl_context.workspace_id,
tmpl_context.folder_id,
tmpl_context.thread_id)
msg = _('{} not un-deleted: {}').format(self._item_type_label, str(e))
tg.flash(msg, CST.STATUS_ERROR)
tg.redirect(back_url)
示例2: put_delete_undo
# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import undelete [as 别名]
def put_delete_undo(self, item_id):
# TODO - CHECK RIGHTS
item_id = int(item_id)
content_api = ContentApi(tmpl_context.current_user, True, True) # Here we do not filter deleted items
item = content_api.get_one(item_id, self._item_type, tmpl_context.workspace)
try:
next_url = self._std_url.format(item.workspace_id, item.parent_id, item.content_id)
msg = _('{} undeleted.').format(self._item_type_label)
content_api.undelete(item)
content_api.save(item, ActionDescription.UNDELETION)
tg.flash(msg, CST.STATUS_OK)
tg.redirect(next_url)
except ValueError as e:
logger.debug(self, 'Exception: {}'.format(e.__str__))
back_url = self._parent_url.format(item.workspace_id, item.parent_id)
msg = _('{} not un-deleted: {}').format(self._item_type_label, str(e))
tg.flash(msg, CST.STATUS_ERROR)
tg.redirect(back_url)
示例3: test_delete_undelete
# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import undelete [as 别名]
def test_delete_undelete(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)
u1id = user1.user_id
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)
# show archived is used at the top end of the test
api = ContentApi(user1, show_deleted=True)
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
transaction.commit()
####
user1 = UserApi(None).get_one(u1id)
workspace = WorkspaceApi(user1).get_one(wid)
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, show_deleted=True)
content2 = api2.get_one(pcid, ContentType.Any, workspace)
with new_revision(content2):
api2.delete(content2)
api2.save(content2)
transaction.commit()
####
user1 = UserApi(None).get_one(u1id)
workspace = WorkspaceApi(user1).get_one(wid)
# show archived is used at the top end of the test
api = ContentApi(user1, show_deleted=True)
u2 = UserApi(None).get_one(u2id)
api2 = ContentApi(u2, show_deleted=True)
updated = api2.get_one(pcid, ContentType.Any, workspace)
eq_(u2id, updated.owner_id,
'the owner id should be {} (found {})'.format(u2id,
updated.owner_id))
eq_(True, updated.is_deleted)
eq_(ActionDescription.DELETION, updated.revision_type)
####
updated2 = api.get_one(pcid, ContentType.Any, workspace)
with new_revision(updated2):
api.undelete(updated2)
api.save(updated2)
eq_(False, updated2.is_deleted)
eq_(ActionDescription.UNDELETION, updated2.revision_type)
eq_(u1id, updated2.owner_id)