本文整理汇总了Python中tracim.lib.content.ContentApi.get_one_revision_filepath方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.get_one_revision_filepath方法的具体用法?Python ContentApi.get_one_revision_filepath怎么用?Python ContentApi.get_one_revision_filepath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim.lib.content.ContentApi
的用法示例。
在下文中一共展示了ContentApi.get_one_revision_filepath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_pdf_one
# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import get_one_revision_filepath [as 别名]
def download_pdf_one(self,
page_id: str,
revision_id: str=None,
*args, **kwargs):
file_id = int(tg.request.controller_state.routing_args.get('file_id'))
revision_id = int(revision_id) if revision_id != 'latest' else None
page = int(page_id)
cache_path = CFG.get_instance().PREVIEW_CACHE_DIR
preview_manager = PreviewManager(cache_path, create_folder=True)
user = tmpl_context.current_user
content_api = ContentApi(user,
show_archived=True,
show_deleted=True)
file = content_api.get_one(file_id, self._item_type)
if revision_id:
file_path = content_api.get_one_revision_filepath(revision_id)
else:
file = content_api.get_one(file_id, self._item_type)
file_path = content_api.get_one_revision_filepath(file.revision_id)
path = preview_manager.get_pdf_preview(file_path=file_path,
page=page)
file_suffix = ''
if page > -1:
file_suffix = '.page-{}'.format(page + 1)
tg.response.headers['Content-Disposition'] = \
'attachment; filename="{}{}.pdf"'.format(
file.label,
file_suffix,
)
with open(path, 'rb') as pdf:
return pdf.read()
示例2: get_one
# 需要导入模块: from tracim.lib.content import ContentApi [as 别名]
# 或者: from tracim.lib.content.ContentApi import get_one_revision_filepath [as 别名]
def get_one(self,
page_id: str='-1',
revision_id: str=None,
size: int=300,
*args, **kwargs):
file_id = int(tg.request.controller_state.routing_args.get('file_id'))
page = int(page_id)
revision_id = int(revision_id) if revision_id != 'latest' else None
cache_path = CFG.get_instance().PREVIEW_CACHE_DIR
preview_manager = PreviewManager(cache_path, create_folder=True)
user = tmpl_context.current_user
content_api = ContentApi(user,
show_archived=True,
show_deleted=True)
if revision_id:
file_path = content_api.get_one_revision_filepath(revision_id)
else:
file = content_api.get_one(file_id, self._item_type)
file_path = content_api.get_one_revision_filepath(file.revision_id)
try:
path = preview_manager.get_jpeg_preview(file_path=file_path,
page=page,
height=size,
width=size)
with open(path, 'rb') as large:
result = large.read()
except PreviewGeneratorException:
result = None
return result