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


Python ContentApi.get_one方法代码示例

本文整理汇总了Python中tracim_backend.lib.core.content.ContentApi.get_one方法的典型用法代码示例。如果您正苦于以下问题:Python ContentApi.get_one方法的具体用法?Python ContentApi.get_one怎么用?Python ContentApi.get_one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tracim_backend.lib.core.content.ContentApi的用法示例。


在下文中一共展示了ContentApi.get_one方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload_file

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [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: update_html_document

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
    def update_html_document(self, context, request: TracimRequest, hapic_data=None) -> ContentInContext:  # nopep8
        """
        update_html_document
        """
        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
        )
        with new_revision(
                session=request.dbsession,
                tm=transaction.manager,
                content=content
        ):
            api.update_content(
                item=content,
                new_label=hapic_data.body.label,
                new_content=hapic_data.body.raw_content,

            )
            api.save(content)
        return api.get_content_in_context(content)
开发者ID:tracim,项目名称:tracim,代码行数:31,代码来源:html_document_controller.py

示例3: archive_content

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def archive_content(
         self,
         context,
         request: TracimRequest,
         hapic_data=None,
 ) -> None:
     """
     Archives a content. The content will be invisible but still available.
     Difference with delete is that optimizing workspace will not delete archived contents
     This action requires the user to be a content manager.
     Note: the content is still accessible but becomes read-only.
     the difference with delete is that optimizing workspace will not delete archived contents
     """
     app_config = request.registry.settings['CFG']
     path_data = hapic_data.path
     api = ContentApi(
         show_archived=True,
         show_deleted=True,
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config,
     )
     content = api.get_one(path_data.content_id, content_type=content_type_list.Any_SLUG)  # nopep8
     with new_revision(
             session=request.dbsession,
             tm=transaction.manager,
             content=content
     ):
         api.archive(content)
     return
开发者ID:tracim,项目名称:tracim,代码行数:32,代码来源:workspace_controller.py

示例4: unarchive_content

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def unarchive_content(
         self,
         context,
         request: TracimRequest,
         hapic_data=None,
 ) -> None:
     """
     Restore a content from archive. The content will be visible and editable again.
     """
     app_config = request.registry.settings['CFG']
     path_data = hapic_data.path
     api = ContentApi(
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config,
         show_archived=True,
         show_deleted=True,
     )
     content = api.get_one(
         path_data.content_id,
         content_type=content_type_list.Any_SLUG
     )
     with new_revision(
             session=request.dbsession,
             tm=transaction.manager,
             content=content
     ):
         api.unarchive(content)
     return
开发者ID:tracim,项目名称:tracim,代码行数:31,代码来源:workspace_controller.py

示例5: account_last_active_content

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def account_last_active_content(self, context, request: TracimRequest, hapic_data=None):  # nopep8
     """
     Get last_active_content for user
     """
     app_config = request.registry.settings['CFG']
     content_filter = hapic_data.query
     api = ContentApi(
         current_user=request.current_user,  # User
         session=request.dbsession,
         config=app_config,
     )
     wapi = WorkspaceApi(
         current_user=request.current_user,  # User
         session=request.dbsession,
         config=app_config,
     )
     workspace = None
     if hapic_data.path.workspace_id:
         workspace = wapi.get_one(hapic_data.path.workspace_id)
     before_content = None
     if content_filter.before_content_id:
         before_content = api.get_one(
             content_id=content_filter.before_content_id,
             workspace=workspace,
             content_type=content_type_list.Any_SLUG
         )
     last_actives = api.get_last_active(
         workspace=workspace,
         limit=content_filter.limit or None,
         before_content=before_content,
     )
     return [
         api.get_content_in_context(content)
         for content in last_actives
     ]
开发者ID:tracim,项目名称:tracim,代码行数:37,代码来源:account_controller.py

示例6: delete_content

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def delete_content(
         self,
         context,
         request: TracimRequest,
         hapic_data=None,
 ) -> None:
     """
     Move a content to the trash. After that, the content will be invisible by default.
     This action requires the user to be a content manager.
     Note: the content is still accessible but becomes read-only.
     """
     app_config = request.registry.settings['CFG']
     path_data = hapic_data.path
     api = ContentApi(
         show_archived=True,
         show_deleted=True,
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config,
     )
     content = api.get_one(
         path_data.content_id,
         content_type=content_type_list.Any_SLUG
     )
     with new_revision(
             session=request.dbsession,
             tm=transaction.manager,
             content=content
     ):
         api.delete(content)
     return
开发者ID:tracim,项目名称:tracim,代码行数:33,代码来源:workspace_controller.py

示例7: get_content

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def get_content(
         self,
         context,
         request: TracimRequest,
         hapic_data=None,
 ) -> None:
     """
     Convenient route allowing to get detail about a content without to known routes associated to its content type.
     This route generate a HTTP 302 with the right url
     """
     app_config = request.registry.settings['CFG']
     api = ContentApi(
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config,
     )
     content = api.get_one(
         content_id=hapic_data.path['content_id'],
         content_type=content_type_list.Any_SLUG
     )
     content_type = content_type_list.get_one_by_slug(content.type).slug
     # TODO - G.M - 2018-08-03 - Jsonify redirect response ?
     raise HTTPFound(
         "{base_url}workspaces/{workspace_id}/{content_type}s/{content_id}".format(
             base_url=BASE_API_V2,
             workspace_id=content.workspace_id,
             content_type=content_type,
             content_id=content.content_id,
         )
     )
开发者ID:tracim,项目名称:tracim,代码行数:32,代码来源:workspace_controller.py

示例8: get_html_document_revisions

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def get_html_document_revisions(
         self,
         context,
         request: TracimRequest,
         hapic_data=None
 ) -> typing.List[RevisionInContext]:
     """
     get html_document revisions
     """
     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
     )
     revisions = content.revisions
     return [
         api.get_revision_in_context(revision)
         for revision in revisions
     ]
开发者ID:tracim,项目名称:tracim,代码行数:28,代码来源:html_document_controller.py

示例9: set_html_document_status

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def set_html_document_status(
         self,
         context,
         request: TracimRequest,
         hapic_data=None
 ) -> None:
     """
     set html_document status
     """
     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
     )
     with new_revision(
             session=request.dbsession,
             tm=transaction.manager,
             content=content
     ):
         api.set_status(
             content,
             hapic_data.body.status,
         )
         api.save(content)
     return
开发者ID:tracim,项目名称:tracim,代码行数:34,代码来源:html_document_controller.py

示例10: preview_pdf_full

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def preview_pdf_full(self, context, request: TracimRequest, hapic_data=None):  # nopep8
     """
     Obtain a full pdf preview (all page) of last revision of content.
     Good pratice for filename is filename is `{label}.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_full_pdf_preview_path(
         content.revision_id,
         file_extension=content.file_extension,
     )
     filename = hapic_data.path.filename
     if not filename or filename == 'raw':
         filename = "{label}.pdf".format(label=content.label)
     return HapicFile(
         file_path=pdf_preview_path,
         filename=filename,
         as_attachment=hapic_data.query.force_download
     )
开发者ID:tracim,项目名称:tracim,代码行数:32,代码来源:file_controller.py

示例11: move_content

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
    def move_content(
            self,
            context,
            request: TracimRequest,
            hapic_data=None,
    ) -> ContentInContext:
        """
        Move a content to specified new place.
        This requires to be content manager in both input and output spaces (which may be the same)
        """
        app_config = request.registry.settings['CFG']
        path_data = hapic_data.path
        move_data = hapic_data.body

        api = ContentApi(
            show_archived=True,
            show_deleted=True,
            current_user=request.current_user,
            session=request.dbsession,
            config=app_config,
        )
        content = api.get_one(
            path_data.content_id,
            content_type=content_type_list.Any_SLUG
        )
        new_parent = api.get_one(
            move_data.new_parent_id, content_type=content_type_list.Any_SLUG
        )

        new_workspace = request.candidate_workspace

        with new_revision(
                session=request.dbsession,
                tm=transaction.manager,
                content=content
        ):
            api.move(
                content,
                new_parent=new_parent,
                new_workspace=new_workspace,
                must_stay_in_same_workspace=False,
            )
        updated_content = api.get_one(
            path_data.content_id,
            content_type=content_type_list.Any_SLUG
        )
        return api.get_content_in_context(updated_content)
开发者ID:tracim,项目名称:tracim,代码行数:49,代码来源:workspace_controller.py

示例12: _get_content

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def _get_content(self, content_id_fetcher):
     content_id = content_id_fetcher()
     api = ContentApi(
         current_user = self.current_user,
         show_deleted = True,
         show_archived = True,
         session = self.dbsession,
         config = self.app_config,
     )
     return api.get_one(
         content_id=content_id,
         workspace=self.current_workspace,
         content_type=content_type_list.Any_SLUG
     )
开发者ID:tracim,项目名称:tracim,代码行数:16,代码来源:request.py

示例13: delete_comment

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def delete_comment(self, context, request: TracimRequest, hapic_data=None):
     """
     Delete comment
     """
     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,
     )
     wapi = WorkspaceApi(
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config,
     )
     workspace = wapi.get_one(hapic_data.path.workspace_id)
     parent = api.get_one(
         hapic_data.path.content_id,
         content_type=content_type_list.Any_SLUG,
         workspace=workspace
     )
     comment = api.get_one(
         hapic_data.path.comment_id,
         content_type=content_type_list.Comment.slug,
         workspace=workspace,
         parent=parent,
     )
     with new_revision(
             session=request.dbsession,
             tm=transaction.manager,
             content=comment
     ):
         api.delete(comment)
     return
开发者ID:tracim,项目名称:tracim,代码行数:38,代码来源:comment_controller.py

示例14: create_file

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [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

示例15: get_html_document

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_one [as 别名]
 def get_html_document(self, context, request: TracimRequest, hapic_data=None) -> ContentInContext:  # nopep8
     """
     Get html document content
     """
     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
     )
     return api.get_content_in_context(content)
开发者ID:tracim,项目名称:tracim,代码行数:19,代码来源:html_document_controller.py


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