本文整理汇总了Python中tracim.lib.content.ContentApi.get_one_from_revision方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.get_one_from_revision方法的具体用法?Python ContentApi.get_one_from_revision怎么用?Python ContentApi.get_one_from_revision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim.lib.content.ContentApi
的用法示例。
在下文中一共展示了ContentApi.get_one_from_revision方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download
# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import get_one_from_revision [as 别名]
def download(self, file_id, revision_id=None):
file_id = int(file_id)
revision_id = int(revision_id) if revision_id!='latest' else None
user = tmpl_context.current_user
workspace = tmpl_context.workspace
content_api = ContentApi(user)
revision_to_send = None
if revision_id:
item = content_api.get_one_from_revision(file_id, self._item_type, workspace, revision_id)
else:
item = content_api.get_one(file_id, self._item_type, workspace)
revision_to_send = None
if item.revision_to_serialize<=0:
for revision in item.revisions:
if not revision_to_send:
revision_to_send = revision
if revision.revision_id>revision_to_send.revision_id:
revision_to_send = revision
else:
for revision in item.revisions:
if revision.revision_id==item.revision_to_serialize:
revision_to_send = revision
break
content_type = 'application/x-download'
if revision_to_send.file_mimetype:
content_type = str(revision_to_send.file_mimetype)
tg.response.headers['Content-type'] = str(revision_to_send.file_mimetype)
tg.response.headers['Content-Type'] = content_type
tg.response.headers['Content-Disposition'] = str('attachment; filename="{}"'.format(revision_to_send.file_name))
return revision_to_send.file_content
示例2: get_one
# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import get_one_from_revision [as 别名]
def get_one(self, page_id, revision_id=None):
page_id = int(page_id)
user = tmpl_context.current_user
workspace = tmpl_context.workspace
workspace_id = tmpl_context.workspace_id
current_user_content = Context(CTX.CURRENT_USER).toDict(user)
current_user_content.roles.sort(key=lambda role: role.workspace.name)
content_api = ContentApi(user)
if revision_id:
page = content_api.get_one_from_revision(page_id, ContentType.Page, workspace, revision_id)
else:
page = content_api.get_one(page_id, ContentType.Page, workspace)
fake_api_breadcrumb = self.get_breadcrumb(page_id)
fake_api_content = DictLikeClass(breadcrumb=fake_api_breadcrumb, current_user=current_user_content)
fake_api = Context(CTX.FOLDER).toDict(fake_api_content)
dictified_page = Context(CTX.PAGE).toDict(page, 'page')
return DictLikeClass(result = dictified_page, fake_api=fake_api)