当前位置: 首页>>代码示例>>Python>>正文


Python ContentApi.update_file_data方法代码示例

本文整理汇总了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
开发者ID:tracim,项目名称:tracim,代码行数:35,代码来源:file_controller.py

示例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)
开发者ID:tracim,项目名称:tracim,代码行数:50,代码来源:file_controller.py


注:本文中的tracim_backend.lib.core.content.ContentApi.update_file_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。