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


Python content.ContentApi类代码示例

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


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

示例1: archive_content

 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,代码行数:30,代码来源:workspace_controller.py

示例2: account_contents_read_status

 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,代码行数:29,代码来源:account_controller.py

示例3: _get_content

    def _get_content(self, content_path_fetcher):
        path = content_path_fetcher()
        content_path = self.reduce_path(path)
        splited_local_path = content_path.strip('/').split('/')
        workspace_name = webdav_convert_file_name_to_bdd(splited_local_path[0])
        wapi = WorkspaceApi(
            current_user=self.current_user,
            session=self.dbsession,
            config=self.app_config,
        )
        workspace = wapi.get_one_by_label(workspace_name)
        parents = []
        if len(splited_local_path) > 2:
            parent_string = splited_local_path[1:-1]
            parents = [webdav_convert_file_name_to_bdd(x) for x in parent_string]

        content_api = ContentApi(
            config=self.app_config,
            current_user=self.current_user,
            session=self.dbsession
        )
        return content_api.get_one_by_filename_and_parent_labels(
            content_label=webdav_convert_file_name_to_bdd(basename(path)),
            content_parent_labels=parents,
            workspace=workspace,
        )
开发者ID:tracim,项目名称:tracim,代码行数:26,代码来源:dav_provider.py

示例4: get_html_document_revisions

 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,代码行数:26,代码来源:html_document_controller.py

示例5: delete_content

 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,代码行数:31,代码来源:workspace_controller.py

示例6: account_last_active_content

 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,代码行数:35,代码来源:account_controller.py

示例7: workspace_content

 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,代码行数:34,代码来源:workspace_controller.py

示例8: get_content

 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,代码行数:30,代码来源:workspace_controller.py

示例9: preview_pdf_full

 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,代码行数:30,代码来源:file_controller.py

示例10: unarchive_content

 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,代码行数:29,代码来源:workspace_controller.py

示例11: test_func__create_new_content_with_notification__ok__nominal_case

    def test_func__create_new_content_with_notification__ok__nominal_case(self):
        uapi = UserApi(
            current_user=None,
            session=self.session,
            config=self.app_config,
        )
        current_user = uapi.get_one_by_email('[email protected]')
        # Create new user with notification enabled on w1 workspace
        wapi = WorkspaceApi(
            current_user=current_user,
            session=self.session,
            config=self.app_config,
        )
        workspace = wapi.get_one_by_label('Recipes')
        user = uapi.get_one_by_email('[email protected]')
        wapi.enable_notifications(user, workspace)

        api = ContentApi(
            current_user=user,
            session=self.session,
            config=self.app_config,
        )
        item = api.create(
            content_type_list.Folder.slug,
            workspace,
            None,
            'parent',
            do_save=True,
            do_notify=False,
        )
        item2 = api.create(
            content_type_list.File.slug,
            workspace,
            item,
            'file1',
            do_save=True,
            do_notify=True,
        )
        # Send mail async from redis queue
        redis = get_redis_connection(
            self.app_config
        )
        queue = get_rq_queue(
            redis,
            'mail_sender',
        )
        worker = SimpleWorker([queue], connection=queue.connection)
        worker.work(burst=True)
        # check mail received
        response = self.get_mailhog_mails()
        headers = response[0]['Content']['Headers']
        assert headers['From'][0] == '"Bob i. via Tracim" <[email protected]>'  # nopep8
        assert headers['To'][0] == 'Global manager <[email protected]>'
        assert headers['Subject'][0] == '[TRACIM] [Recipes] file1 (Open)'
        assert headers['References'][0] == '[email protected]'
        assert headers['Reply-to'][0] == '"Bob i. & all members of Recipes" <[email protected]>'  # nopep8
开发者ID:tracim,项目名称:tracim,代码行数:56,代码来源:test_mail_notification.py

示例12: is_editable

 def is_editable(self) -> bool:
     from tracim_backend.lib.core.content import ContentApi
     content_api = ContentApi(
         current_user=self._user,
         session=self.dbsession,
         config=self.config,
         show_deleted=True,
         show_archived=True,
         show_active=True,
         show_temporary=True,
     )
     return content_api.is_editable(self.content)
开发者ID:tracim,项目名称:tracim,代码行数:12,代码来源:context_models.py

示例13: exists

    def exists(self, path, environ) -> bool:
        """
        Called by wsgidav to check if a certain path is linked to a _DAVResource
        """

        tracim_context = environ['tracim_context']
        tracim_context.set_path(path)
        path = normpath(path)
        working_path = tracim_context.reduce_path(path)
        root_path = environ['http_authenticator.realm']
        parent_path = dirname(working_path)
        user = tracim_context.current_user
        session = tracim_context.dbsession
        if path == root_path:
            return True

        try:
            workspace = tracim_context.current_workspace
        except WorkspaceNotFound:
            workspace = None

        if parent_path == root_path or workspace is None:
            return workspace is not None

        # TODO bastien: Arnaud avait mis a True, verif le comportement
        # lorsque l'on explore les dossiers archive et deleted
        content_api = ContentApi(
            current_user=user,
            session=session,
            config=self.app_config,
            show_archived=False,
            show_deleted=False
        )

        revision_id = re.search(r'/\.history/[^/]+/\((\d+) - [a-zA-Z]+\) ([^/].+)$', path)

        is_archived = self.is_path_archive(path)

        is_deleted = self.is_path_delete(path)

        if revision_id:
            revision_id = revision_id.group(1)
            content = content_api.get_one_revision(revision_id)
        else:
            try:
                content = tracim_context.current_content
            except ContentNotFound:
                content = None

        return content is not None \
            and content.is_deleted == is_deleted \
            and content.is_archived == is_archived
开发者ID:tracim,项目名称:tracim,代码行数:52,代码来源:dav_provider.py

示例14: test_func__create_comment_with_notification__ok__nominal_case

    def test_func__create_comment_with_notification__ok__nominal_case(self):
        uapi = UserApi(
            current_user=None,
            session=self.session,
            config=self.app_config,
        )
        current_user = uapi.get_one_by_email('[email protected]')
        # set admin as french, useful to verify if i18n work properly
        current_user.lang = 'fr'
        # Create new user with notification enabled on w1 workspace
        wapi = WorkspaceApi(
            current_user=current_user,
            session=self.session,
            config=self.app_config,
        )
        workspace = wapi.get_one_by_label('Recipes')
        user = uapi.get_one_by_email('[email protected]')
        wapi.enable_notifications(user, workspace)

        api = ContentApi(
            current_user=user,
            session=self.session,
            config=self.app_config,
        )
        item = api.create(
            content_type_list.Folder.slug,
            workspace,
            None,
            'parent',
            do_save=True,
            do_notify=False,
        )
        item2 = api.create(
            content_type_list.File.slug,
            workspace,
            item,
            'file1',
            do_save=True,
            do_notify=False,
        )
        api.create_comment(parent=item2, content='My super comment', do_save=True, do_notify=True)
        transaction.commit()

        # check mail received
        response = self.get_mailhog_mails()
        headers = response[0]['Content']['Headers']
        assert headers['From'][0] == '"Bob i. via Tracim" <[email protected]>'  # nopep8
        assert headers['To'][0] == 'Global manager <[email protected]>'
        assert headers['Subject'][0] == '[TRACIM] [Recipes] file1 (Open)'
        assert headers['References'][0] == '[email protected]'
        assert headers['Reply-to'][0] == '"Bob i. & all members of Recipes" <[email protected]>'  # nopep8
开发者ID:tracim,项目名称:tracim,代码行数:51,代码来源:test_mail_notification.py

示例15: set_account_content_as_unread

 def set_account_content_as_unread(self, context, request: TracimRequest, hapic_data=None):  # nopep8
     """
     set user_read status of content to unread
     """
     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,
     )
     api.mark_unread(request.current_content, do_flush=True)
     return
开发者ID:tracim,项目名称:tracim,代码行数:14,代码来源:account_controller.py


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