本文整理汇总了Python中tracim_backend.lib.core.content.ContentApi.get_pdf_preview_path方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.get_pdf_preview_path方法的具体用法?Python ContentApi.get_pdf_preview_path怎么用?Python ContentApi.get_pdf_preview_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim_backend.lib.core.content.ContentApi
的用法示例。
在下文中一共展示了ContentApi.get_pdf_preview_path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preview_pdf
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_pdf_preview_path [as 别名]
def preview_pdf(self, context, request: TracimRequest, hapic_data=None):
"""
Obtain a specific page pdf preview of last revision of content.
Good pratice for filename is filename is `{label}_page_{page_number}.pdf`.
Default filename value is 'raw' (without file extension) or nothing.
"""
app_config = request.registry.settings['CFG']
api = ContentApi(
show_archived=True,
show_deleted=True,
current_user=request.current_user,
session=request.dbsession,
config=app_config,
)
content = api.get_one(
hapic_data.path.content_id,
content_type=content_type_list.Any_SLUG
)
pdf_preview_path = api.get_pdf_preview_path(
content.content_id,
content.revision_id,
page_number=hapic_data.query.page,
file_extension=content.file_extension,
)
filename = hapic_data.path.filename
if not filename or filename == 'raw':
filename = "{label}_page_{page_number}.pdf".format(
label=content.label,
page_number=hapic_data.query.page
)
return HapicFile(
file_path=pdf_preview_path,
filename=filename,
as_attachment=hapic_data.query.force_download
)