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


Python ContentApi.get_content_in_context方法代码示例

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


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

示例1: update_html_document

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

示例2: account_contents_read_status

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_content_in_context [as 别名]
 def account_contents_read_status(self, context, request: TracimRequest, hapic_data=None):  # nopep8
     """
     get user_read status of contents
     """
     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)
     last_actives = api.get_last_active(
         workspace=workspace,
         limit=None,
         before_content=None,
         content_ids=hapic_data.query.content_ids or None
     )
     return [
         api.get_content_in_context(content)
         for content in last_actives
     ]
开发者ID:tracim,项目名称:tracim,代码行数:31,代码来源:account_controller.py

示例3: workspace_content

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_content_in_context [as 别名]
 def workspace_content(
         self,
         context,
         request: TracimRequest,
         hapic_data=None,
 ) -> typing.List[ContentInContext]:
     """
     return a list of contents of the space.
     This is NOT the full content list: by default, returned contents are the ones at root level.
     In order to get contents in a given folder, then use parent_id query filter.
     You can also show.hide archived/deleted contents.
     """
     app_config = request.registry.settings['CFG']
     content_filter = hapic_data.query
     api = ContentApi(
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config,
         show_archived=content_filter.show_archived,
         show_deleted=content_filter.show_deleted,
         show_active=content_filter.show_active,
     )
     contents = api.get_all(
         parent_ids=content_filter.parent_ids,
         complete_path_to_id=content_filter.complete_path_to_id,
         workspace=request.current_workspace,
         content_type=content_filter.content_type or content_type_list.Any_SLUG,
         label=content_filter.label,
         order_by_properties=[Content.label]
     )
     contents = [
         api.get_content_in_context(content) for content in contents
     ]
     return contents
开发者ID:tracim,项目名称:tracim,代码行数:36,代码来源:workspace_controller.py

示例4: account_last_active_content

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

示例5: create_file

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

示例6: move_content

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

示例7: get_html_document

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

示例8: content_comments

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_content_in_context [as 别名]
    def content_comments(self, context, request: TracimRequest, hapic_data=None):
        """
        Get all comments related to a content in asc order (first is the oldest)
        """

        # login = hapic_data.body
        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
        )
        comments = content.get_comments()
        comments.sort(key=lambda comment: comment.created)
        return [api.get_content_in_context(comment)
                for comment in comments
        ]
开发者ID:tracim,项目名称:tracim,代码行数:25,代码来源:comment_controller.py

示例9: create_generic_empty_content

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_content_in_context [as 别名]
 def create_generic_empty_content(
         self,
         context,
         request: TracimRequest,
         hapic_data=None,
 ) -> ContentInContext:
     """
     Creates a generic empty content. The minimum viable content has a label and a content type.
     Creating a content generally starts with a request to this endpoint.
     For specific contents like files, it is recommended to use the dedicated endpoint.
     This feature is accessible to contributors and higher role only.
     """
     app_config = request.registry.settings['CFG']
     creation_data = hapic_data.body
     api = ContentApi(
         current_user=request.current_user,
         session=request.dbsession,
         config=app_config
     )
     parent = None
     if creation_data.parent_id:
         try:
             parent = api.get_one(content_id=creation_data.parent_id, content_type=content_type_list.Any_SLUG)  # nopep8
         except ContentNotFound as exc:
             raise ParentNotFound(
                 'Parent with content_id {} not found'.format(creation_data.parent_id)
             ) from exc
     content = api.create(
         label=creation_data.label,
         content_type_slug=creation_data.content_type,
         workspace=request.current_workspace,
         parent=parent,
     )
     api.save(content, ActionDescription.CREATION)
     content = api.get_content_in_context(content)
     return content
开发者ID:tracim,项目名称:tracim,代码行数:38,代码来源:workspace_controller.py

示例10: add_comment

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import get_content_in_context [as 别名]
 def add_comment(self, context, request: TracimRequest, hapic_data=None):
     """
     Add new comment
     """
     # login = hapic_data.body
     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
     )
     comment = api.create_comment(
         content.workspace,
         content,
         hapic_data.body.raw_content,
         do_save=True,
     )
     return api.get_content_in_context(comment)
开发者ID:tracim,项目名称:tracim,代码行数:26,代码来源:comment_controller.py


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