本文整理汇总了Python中tracim_backend.lib.core.content.ContentApi.update_file_data方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.update_file_data方法的具体用法?Python ContentApi.update_file_data怎么用?Python ContentApi.update_file_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim_backend.lib.core.content.ContentApi
的用法示例。
在下文中一共展示了ContentApi.update_file_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_file
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import update_file_data [as 别名]
def upload_file(self, context, request: TracimRequest, hapic_data=None):
"""
Upload a new version of raw file of content. This will create a new
revision.
Good pratice for filename is filename is `{label}{file_extension}` or `{filename}`.
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
)
_file = hapic_data.files.files
with new_revision(
session=request.dbsession,
tm=transaction.manager,
content=content
):
api.update_file_data(
content,
new_filename=_file.filename,
new_mimetype=_file.type,
new_content=_file.file,
)
api.save(content)
return
示例2: create_file
# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import update_file_data [as 别名]
def create_file(self, context, request: TracimRequest, hapic_data=None):
"""
Create a file .This will create 2 new revision.
"""
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,
)
_file = hapic_data.files.files
parent_id = hapic_data.forms.parent_id
api = ContentApi(
current_user=request.current_user,
session=request.dbsession,
config=app_config
)
parent = None # type: typing.Optional['Content']
if parent_id:
try:
parent = api.get_one(content_id=parent_id, content_type=content_type_list.Any_SLUG) # nopep8
except ContentNotFound as exc:
raise ParentNotFound(
'Parent with content_id {} not found'.format(parent_id)
) from exc
content = api.create(
filename=_file.filename,
content_type_slug=FILE_TYPE,
workspace=request.current_workspace,
parent=parent,
)
api.save(content, ActionDescription.CREATION)
with new_revision(
session=request.dbsession,
tm=transaction.manager,
content=content
):
api.update_file_data(
content,
new_filename=_file.filename,
new_mimetype=_file.type,
new_content=_file.file,
)
return api.get_content_in_context(content)