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


Python ContentApi.save方法代码示例

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


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

示例1: update_html_document

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

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

示例3: set_html_document_status

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

示例4: create_file

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

示例5: create_generic_empty_content

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

示例6: insert

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import save [as 别名]
    def insert(self):
        admin = self._session.query(User) \
            .filter(User.email == '[email protected]') \
            .one()
        bob = self._session.query(User) \
            .filter(User.email == '[email protected]') \
            .one()
        john_the_reader = self._session.query(User) \
            .filter(User.email == '[email protected]') \
            .one()

        admin_workspace_api = WorkspaceApi(
            current_user=admin,
            session=self._session,
            config=self._config,
        )
        bob_workspace_api = WorkspaceApi(
            current_user=bob,
            session=self._session,
            config=self._config
        )
        content_api = ContentApi(
            current_user=admin,
            session=self._session,
            config=self._config
        )
        bob_content_api = ContentApi(
            current_user=bob,
            session=self._session,
            config=self._config
        )
        reader_content_api = ContentApi(
            current_user=john_the_reader,
            session=self._session,
            config=self._config
        )
        role_api = RoleApi(
            current_user=admin,
            session=self._session,
            config=self._config,
        )

        # Workspaces
        business_workspace = admin_workspace_api.create_workspace(
            'Business',
            description='All importants documents',
            save_now=True,
        )
        recipe_workspace = admin_workspace_api.create_workspace(
            'Recipes',
            description='Our best recipes',
            save_now=True,
        )
        other_workspace = bob_workspace_api.create_workspace(
            'Others',
            description='Other Workspace',
            save_now=True,
        )

        # Workspaces roles
        role_api.create_one(
            user=bob,
            workspace=recipe_workspace,
            role_level=UserRoleInWorkspace.CONTENT_MANAGER,
            with_notif=False,
        )
        role_api.create_one(
            user=john_the_reader,
            workspace=recipe_workspace,
            role_level=UserRoleInWorkspace.READER,
            with_notif=False,
        )
        # Folders

        tool_workspace = content_api.create(
            content_type_slug=content_type_list.Folder.slug,
            workspace=business_workspace,
            label='Tools',
            do_save=True,
            do_notify=False,
        )
        menu_workspace = content_api.create(
            content_type_slug=content_type_list.Folder.slug,
            workspace=business_workspace,
            label='Menus',
            do_save=True,
            do_notify=False,
        )

        dessert_folder = content_api.create(
            content_type_slug=content_type_list.Folder.slug,
            workspace=recipe_workspace,
            label='Desserts',
            do_save=True,
            do_notify=False,
        )
        salads_folder = content_api.create(
            content_type_slug=content_type_list.Folder.slug,
            workspace=recipe_workspace,
            label='Salads',
#.........这里部分代码省略.........
开发者ID:tracim,项目名称:tracim,代码行数:103,代码来源:content.py

示例7: FileResource

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import save [as 别名]

#.........这里部分代码省略.........
            checker = can_move_content

        try:
            checker.check(self.tracim_context)
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN)

        try:
            with new_revision(
                content=self.content,
                tm=transaction.manager,
                session=self.session,
            ):
                # INFO - G.M - 2018-03-09 - First, renaming file if needed
                if basename(destpath) != self.getDisplayName():

                    new_filename = webdav_convert_file_name_to_bdd(basename(destpath))
                    regex_file_extension = re.compile(
                        '(?P<label>.*){}'.format(
                            re.escape(self.content.file_extension)))
                    same_extension = regex_file_extension.match(new_filename)
                    if same_extension:
                        new_label = same_extension.group('label')
                        new_file_extension = self.content.file_extension
                    else:
                        new_label, new_file_extension = os.path.splitext(
                            new_filename)

                    self.content_api.update_content(
                        self.content,
                        new_label=new_label,
                    )
                    self.content.file_extension = new_file_extension
                    self.content_api.save(self.content)

                # INFO - G.M - 2018-03-09 - Moving file if needed
                destination_workspace = self.tracim_context.candidate_workspace
                try:
                    destination_parent = self.tracim_context.candidate_parent_content
                except ContentNotFound:
                    destination_parent = None
                if destination_parent != parent or destination_workspace != workspace:  # nopep8
                    #  INFO - G.M - 12-03-2018 - Avoid moving the file "at the same place"  # nopep8
                    #  if the request does not result in a real move.
                    self.content_api.move(
                        item=self.content,
                        new_parent=destination_parent,
                        must_stay_in_same_workspace=False,
                        new_workspace=destination_workspace
                    )
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN) from exc

        transaction.commit()

    def copyMoveSingle(self, destpath, isMove):
        if isMove:
            # INFO - G.M - 12-03-2018 - This case should not happen
            # As far as moveRecursive method exist, all move should not go
            # through this method. If such case appear, try replace this to :
            ####
            # self.move_file(destpath)
            # return
            ####
            raise NotImplemented('Feature not available')
开发者ID:tracim,项目名称:tracim,代码行数:69,代码来源:resources.py

示例8: WorkspaceResource

# 需要导入模块: from tracim_backend.lib.core.content import ContentApi [as 别名]
# 或者: from tracim_backend.lib.core.content.ContentApi import save [as 别名]

#.........这里部分代码省略.........
        # return item
        return FakeFileStream(
            session=self.session,
            file_name=fixed_file_name,
            content_api=self.content_api,
            workspace=self.workspace,
            content=content,
            parent=self.content,
            path=self.path + '/' + fixed_file_name
        )

    @webdav_check_right(is_content_manager)
    def createCollection(self, label: str) -> 'FolderResource':
        """
        Create a new folder for the current workspace. As it's not possible for the user to choose
        which types of content are allowed in this folder, we allow allow all of them.

        This method return the DAVCollection created.
        """

        if '/.deleted/' in self.path or '/.archived/' in self.path:
            raise DAVError(HTTP_FORBIDDEN)
        folder_label = webdav_convert_file_name_to_bdd(label)
        try:
            folder = self.content_api.create(
                content_type_slug=content_type_list.Folder.slug,
                workspace=self.workspace,
                label=folder_label,
                parent=self.content
            )
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN) from exc

        self.content_api.save(folder)

        transaction.commit()
        # fixed_path
        folder_path = '%s/%s' % (self.path, webdav_convert_file_name_to_display(label))
        # return item
        return FolderResource(
            folder_path,
            self.environ,
            content=folder,
            tracim_context=self.tracim_context,
            workspace=self.workspace,
        )

    def delete(self):
        """For now, it is not possible to delete a workspace through the webdav client."""
        # FIXME - G.M - 2018-12-11 - For an unknown reason current_workspace
        # of tracim_context is here invalid.
        self.tracim_context._current_workspace = self.workspace
        try:
            can_delete_workspace.check(self.tracim_context)
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN)
        raise DAVError(HTTP_FORBIDDEN)

    def supportRecursiveMove(self, destpath):
        return True

    def moveRecursive(self, destpath):
        # INFO - G.M - 2018-12-11 - We only allow renaming
        if dirname(normpath(destpath)) == self.environ['http_authenticator.realm']:
            # FIXME - G.M - 2018-12-11 - For an unknown reason current_workspace
            # of tracim_context is here invalid.
开发者ID:tracim,项目名称:tracim,代码行数:70,代码来源:resources.py


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