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


Python split.SplitMongoModuleStore类代码示例

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


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

示例1: delete_item

    def delete_item(self, location, user_id, revision=None, **kwargs):
        """
        Delete the given item from persistence. kwargs allow modulestore specific parameters.

        Args:
            location: UsageKey of the item to be deleted
            user_id: id of the user deleting the item
            revision:
                None - deletes the item and its subtree, and updates the parents per description above
                ModuleStoreEnum.RevisionOption.published_only - removes only Published versions
                ModuleStoreEnum.RevisionOption.all - removes both Draft and Published parents
                    currently only provided by contentstore.views.item.orphan_handler
                Otherwise, raises a ValueError.
        """
        with self.bulk_operations(location.course_key):
            if revision == ModuleStoreEnum.RevisionOption.published_only:
                branches_to_delete = [ModuleStoreEnum.BranchName.published]
            elif revision == ModuleStoreEnum.RevisionOption.all:
                branches_to_delete = [ModuleStoreEnum.BranchName.published, ModuleStoreEnum.BranchName.draft]
            elif revision is None:
                branches_to_delete = [ModuleStoreEnum.BranchName.draft]
            else:
                raise UnsupportedRevisionError(
                    [
                        None,
                        ModuleStoreEnum.RevisionOption.published_only,
                        ModuleStoreEnum.RevisionOption.all
                    ]
                )

            for branch in branches_to_delete:
                branched_location = location.for_branch(branch)
                parent_loc = self.get_parent_location(branched_location)
                SplitMongoModuleStore.delete_item(self, branched_location, user_id)
                self._auto_publish_no_children(parent_loc, parent_loc.category, user_id, **kwargs)
开发者ID:NATI-UNIFOR,项目名称:edx-platform,代码行数:35,代码来源:split_draft.py

示例2: delete_item

    def delete_item(self, location, user_id, revision=None, skip_auto_publish=False, **kwargs):
        """
        Delete the given item from persistence. kwargs allow modulestore specific parameters.

        Args:
            location: UsageKey of the item to be deleted
            user_id: id of the user deleting the item
            revision:
                None - deletes the item and its subtree, and updates the parents per description above
                ModuleStoreEnum.RevisionOption.published_only - removes only Published versions
                ModuleStoreEnum.RevisionOption.all - removes both Draft and Published parents
                    currently only provided by contentstore.views.item.orphan_handler
                Otherwise, raises a ValueError.
        """
        with self.bulk_operations(location.course_key):
            if isinstance(location, LibraryUsageLocator):
                branches_to_delete = [ModuleStoreEnum.BranchName.library]  # Libraries don't yet have draft/publish support
            elif revision == ModuleStoreEnum.RevisionOption.published_only:
                branches_to_delete = [ModuleStoreEnum.BranchName.published]
            elif revision == ModuleStoreEnum.RevisionOption.all:
                branches_to_delete = [ModuleStoreEnum.BranchName.published, ModuleStoreEnum.BranchName.draft]
            elif revision is None:
                branches_to_delete = [ModuleStoreEnum.BranchName.draft]
                draft_location = location.for_branch(ModuleStoreEnum.BranchName.draft)
                try:
                    item = self.get_item(draft_location)
                    if getattr(item, 'has_children', False):
                        # If item have has_published_version then delete published children also.
                        if self.has_published_version(item):
                            branches_to_delete.insert(0, ModuleStoreEnum.BranchName.published)
                except ItemNotFoundError:
                    # Raises ValueError as in function description
                    raise ValueError("Cannot delete a block that does not exist")
            else:
                raise UnsupportedRevisionError(
                    [
                        None,
                        ModuleStoreEnum.RevisionOption.published_only,
                        ModuleStoreEnum.RevisionOption.all
                    ]
                )

            self._flag_publish_event(location.course_key)
            for branch in branches_to_delete:
                branched_location = location.for_branch(branch)
                parent_loc = self.get_parent_location(branched_location)
                SplitMongoModuleStore.delete_item(self, branched_location, user_id)
                # publish parent w/o child if deleted element is direct only (not based on type of parent)
                # publish vertical to behave more like the old mongo/draft modulestore - TNL-2593
                if (
                        branch == ModuleStoreEnum.BranchName.draft and
                        branched_location.block_type in (DIRECT_ONLY_CATEGORIES + ['vertical']) and
                        parent_loc and
                        not skip_auto_publish
                ):
                    # will publish if its not an orphan
                    self.publish(parent_loc.version_agnostic(), user_id, blacklist=EXCLUDE_ALL, **kwargs)
开发者ID:nikolicnikola,项目名称:edx-platform,代码行数:57,代码来源:split_draft.py

示例3: get_library

 def get_library(self, library_id, depth=0, head_validation=True, **kwargs):
     if not head_validation and library_id.version_guid:
         return SplitMongoModuleStore.get_library(
             self, library_id, depth=depth, head_validation=head_validation, **kwargs
         )
     library_id = self._map_revision_to_branch(library_id)
     return super(DraftVersioningModuleStore, self).get_library(library_id, depth=depth, **kwargs)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:7,代码来源:split_draft.py

示例4: delete_item

    def delete_item(self, location, user_id, revision=None, **kwargs):
        """
        Delete the given item from persistence. kwargs allow modulestore specific parameters.

        Args:
            location: UsageKey of the item to be deleted
            user_id: id of the user deleting the item
            revision:
                None - deletes the item and its subtree, and updates the parents per description above
                ModuleStoreEnum.RevisionOption.published_only - removes only Published versions
                ModuleStoreEnum.RevisionOption.all - removes both Draft and Published parents
                    currently only provided by contentstore.views.item.orphan_handler
                Otherwise, raises a ValueError.
        """
        with self.bulk_operations(location.course_key):
            if isinstance(location, LibraryUsageLocator):
                branches_to_delete = [ModuleStoreEnum.BranchName.library]  # Libraries don't yet have draft/publish support
            elif revision == ModuleStoreEnum.RevisionOption.published_only:
                branches_to_delete = [ModuleStoreEnum.BranchName.published]
            elif revision == ModuleStoreEnum.RevisionOption.all:
                branches_to_delete = [ModuleStoreEnum.BranchName.published, ModuleStoreEnum.BranchName.draft]
            elif revision is None:
                branches_to_delete = [ModuleStoreEnum.BranchName.draft]
            else:
                raise UnsupportedRevisionError(
                    [
                        None,
                        ModuleStoreEnum.RevisionOption.published_only,
                        ModuleStoreEnum.RevisionOption.all
                    ]
                )

            self._flag_publish_event(location.course_key)
            for branch in branches_to_delete:
                branched_location = location.for_branch(branch)
                parent_loc = self.get_parent_location(branched_location)
                SplitMongoModuleStore.delete_item(self, branched_location, user_id)
                # publish parent w/o child if deleted element is direct only (not based on type of parent)
                if branch == ModuleStoreEnum.BranchName.draft and branched_location.block_type in DIRECT_ONLY_CATEGORIES:
                    self.publish(parent_loc.version_agnostic(), user_id, blacklist=EXCLUDE_ALL, **kwargs)

        # Remove this location from the courseware search index so that searches
        # will refrain from showing it as a result
        CoursewareSearchIndexer.add_to_search_index(self, location, delete=True)
开发者ID:Taxellool,项目名称:edx-platform,代码行数:44,代码来源:split_draft.py

示例5: setUp

 def setUp(self):
     super(TestMigration, self).setUp()
     self.loc_mapper = LocMapperStore(**self.db_config)
     self.old_mongo = MongoModuleStore(**self.modulestore_options)
     self.draft_mongo = DraftModuleStore(**self.modulestore_options)
     self.split_mongo = SplitMongoModuleStore(
         loc_mapper=self.loc_mapper, **self.modulestore_options
     )
     self.migrator = SplitMigrator(self.split_mongo, self.old_mongo, self.draft_mongo, self.loc_mapper)
     self.course_location = None
     self.create_source_course()
开发者ID:Cabris,项目名称:edx-platform,代码行数:11,代码来源:test_split_migrator.py

示例6: setUp

 def setUp(self):
     super(TestMigration, self).setUp()
     # pylint: disable=W0142
     self.loc_mapper = LocMapperStore(test_location_mapper.TrivialCache(), **self.db_config)
     self.old_mongo = MongoModuleStore(self.db_config, **self.modulestore_options)
     self.draft_mongo = DraftModuleStore(self.db_config, **self.modulestore_options)
     self.split_mongo = SplitMongoModuleStore(
         doc_store_config=self.db_config, loc_mapper=self.loc_mapper, **self.modulestore_options
     )
     self.migrator = SplitMigrator(self.split_mongo, self.old_mongo, self.draft_mongo, self.loc_mapper)
     self.course_location = None
     self.create_source_course()
开发者ID:Bachmann1234,项目名称:edx-platform,代码行数:12,代码来源:test_split_migrator.py

示例7: setUp

 def setUp(self):
     super(TestMigration, self).setUp()
     noop_cache = mock.Mock(spec=['get', 'set_many'])
     noop_cache.configure_mock(**{'get.return_value': None})
     # pylint: disable=W0142
     self.loc_mapper = LocMapperStore(noop_cache, **self.db_config)
     self.old_mongo = MongoModuleStore(self.db_config, **self.modulestore_options)
     self.draft_mongo = DraftModuleStore(self.db_config, **self.modulestore_options)
     self.split_mongo = SplitMongoModuleStore(
         doc_store_config=self.db_config,
         loc_mapper=self.loc_mapper,
         **self.modulestore_options
     )
     self.migrator = SplitMigrator(self.split_mongo, self.old_mongo, self.draft_mongo, self.loc_mapper)
     self.course_location = None
     self.create_source_course()
开发者ID:6thfdwp,项目名称:edx-platform,代码行数:16,代码来源:test_split_migrator.py

示例8: setUp

    def setUp(self):
        self.db_config['collection'] = 'modulestore{0}'.format(uuid.uuid4().hex[:5])

        self.userid = random.getrandbits(32)
        super(SplitWMongoCourseBoostrapper, self).setUp()
        self.split_mongo = SplitMongoModuleStore(
            self.db_config,
            **self.modulestore_options
        )
        self.addCleanup(self.split_mongo.db.connection.close)
        self.addCleanup(self.tear_down_split)
        self.old_mongo = MongoModuleStore(self.db_config, **self.modulestore_options)
        self.draft_mongo = DraftMongoModuleStore(self.db_config, **self.modulestore_options)
        self.addCleanup(self.tear_down_mongo)
        self.old_course_key = None
        self.runtime = None
        self._create_course()
开发者ID:PaoloC68,项目名称:edx-platform,代码行数:17,代码来源:test_split_w_old_mongo.py

示例9: setUp

 def setUp(self):
     self.user_id = random.getrandbits(32)
     super(SplitWMongoCourseBootstrapper, self).setUp()
     self.split_mongo = SplitMongoModuleStore(
         None,
         self.db_config,
         **self.modulestore_options
     )
     self.addCleanup(self.split_mongo._drop_database)  # pylint: disable=protected-access
     self.draft_mongo = DraftMongoModuleStore(
         None, self.db_config, branch_setting_func=lambda: ModuleStoreEnum.Branch.draft_preferred,
         metadata_inheritance_cache_subsystem=MemoryCache(),
         **self.modulestore_options
     )
     self.addCleanup(self.draft_mongo._drop_database)  # pylint: disable=protected-access
     self.old_course_key = None
     self.runtime = None
     self._create_course()
开发者ID:cmscom,项目名称:edx-platform,代码行数:18,代码来源:test_split_w_old_mongo.py

示例10: setUp

    def setUp(self):
        self.db_config['collection'] = 'modulestore{0}'.format(uuid.uuid4().hex[:5])

        self.user_id = random.getrandbits(32)
        super(SplitWMongoCourseBoostrapper, self).setUp()
        self.split_mongo = SplitMongoModuleStore(
            None,
            self.db_config,
            **self.modulestore_options
        )
        self.addCleanup(self.split_mongo.db.connection.close)
        self.addCleanup(self.tear_down_split)
        self.draft_mongo = DraftMongoModuleStore(
            None, self.db_config, branch_setting_func=lambda: ModuleStoreEnum.Branch.draft_preferred,
            metadata_inheritance_cache_subsystem=MemoryCache(),
            **self.modulestore_options
        )
        self.addCleanup(self.tear_down_mongo)
        self.old_course_key = None
        self.runtime = None
        self._create_course()
开发者ID:IET-OU,项目名称:edx-platform,代码行数:21,代码来源:test_split_w_old_mongo.py

示例11: SplitWMongoCourseBoostrapper

class SplitWMongoCourseBoostrapper(unittest.TestCase):
    """
    Helper for tests which need to construct split mongo & old mongo based courses to get interesting internal structure.
    Override _create_course and after invoking the super() _create_course, have it call _create_item for
    each xblock you want in the course.
    This class ensures the db gets created, opened, and cleaned up in addition to creating the course

    Defines the following attrs on self:
    * user_id: a random non-registered mock user id
    * split_mongo: a pointer to the split mongo instance
    * draft_mongo: a pointer to the old draft instance
    * split_course_key (CourseLocator): of the new course
    * old_course_key: the SlashSpecifiedCourseKey for the course
    """
        # Snippet of what would be in the django settings envs file
    db_config = {
        'host': MONGO_HOST,
        'port': MONGO_PORT_NUM,
        'db': 'test_xmodule',
    }

    modulestore_options = {
        'default_class': 'xmodule.raw_module.RawDescriptor',
        'fs_root': '',
        'render_template': mock.Mock(return_value=""),
        'xblock_mixins': (InheritanceMixin,)
    }

    split_course_key = CourseLocator('test_org', 'test_course', 'runid', branch=ModuleStoreEnum.BranchName.draft)

    def setUp(self):
        self.db_config['collection'] = 'modulestore{0}'.format(uuid.uuid4().hex[:5])

        self.user_id = random.getrandbits(32)
        super(SplitWMongoCourseBoostrapper, self).setUp()
        self.split_mongo = SplitMongoModuleStore(
            None,
            self.db_config,
            **self.modulestore_options
        )
        self.addCleanup(self.split_mongo.db.connection.close)
        self.addCleanup(self.tear_down_split)
        self.draft_mongo = DraftMongoModuleStore(
            None, self.db_config, branch_setting_func=lambda: ModuleStoreEnum.Branch.draft_preferred, **self.modulestore_options
        )
        self.addCleanup(self.tear_down_mongo)
        self.old_course_key = None
        self.runtime = None
        self._create_course()

    def tear_down_split(self):
        """
        Remove the test collections, close the db connection
        """
        split_db = self.split_mongo.db
        split_db.drop_collection(split_db.course_index)
        split_db.drop_collection(split_db.structures)
        split_db.drop_collection(split_db.definitions)

    def tear_down_mongo(self):
        """
        Remove the test collections, close the db connection
        """
        split_db = self.split_mongo.db
        # old_mongo doesn't give a db attr, but all of the dbs are the same
        split_db.drop_collection(self.draft_mongo.collection)

    def _create_item(self, category, name, data, metadata, parent_category, parent_name, draft=True, split=True):
        """
        Create the item of the given category and block id in split and old mongo, add it to the optional
        parent. The parent category is only needed because old mongo requires it for the id.

        Note: if draft = False, it will create the draft and then publish it; so, it will overwrite any
        existing draft for both the new item and the parent
        """
        location = self.old_course_key.make_usage_key(category, name)
        self.draft_mongo.create_item(
            self.user_id,
            location.course_key,
            location.block_type,
            block_id=location.block_id,
            definition_data=data,
            metadata=metadata,
            runtime=self.runtime
        )
        if not draft:
            self.draft_mongo.publish(location, self.user_id)
        if isinstance(data, basestring):
            fields = {'data': data}
        else:
            fields = data.copy()
        fields.update(metadata)
        if parent_name:
            # add child to parent in mongo
            parent_location = self.old_course_key.make_usage_key(parent_category, parent_name)
            parent = self.draft_mongo.get_item(parent_location)
            parent.children.append(location)
            self.draft_mongo.update_item(parent, self.user_id)
            if not draft:
                self.draft_mongo.publish(parent_location, self.user_id)
#.........这里部分代码省略.........
开发者ID:AdityaKashyap,项目名称:edx-platform,代码行数:101,代码来源:test_split_w_old_mongo.py

示例12: TestMigration

class TestMigration(unittest.TestCase):
    """
    Test the split migrator
    """

    # Snippet of what would be in the django settings envs file
    db_config = {
        'host': 'localhost',
        'db': 'test_xmodule',
        'collection': 'modulestore{0}'.format(uuid.uuid4().hex[:5]),
    }

    modulestore_options = {
        'default_class': 'xmodule.raw_module.RawDescriptor',
        'fs_root': '',
        'render_template': mock.Mock(return_value=""),
        'xblock_mixins': (InheritanceMixin,)
    }

    def setUp(self):
        super(TestMigration, self).setUp()
        self.loc_mapper = LocMapperStore(**self.db_config)
        self.old_mongo = MongoModuleStore(self.db_config, **self.modulestore_options)
        self.draft_mongo = DraftModuleStore(self.db_config, **self.modulestore_options)
        self.split_mongo = SplitMongoModuleStore(
            doc_store_config=self.db_config,
            loc_mapper=self.loc_mapper,
            **self.modulestore_options
        )
        self.migrator = SplitMigrator(self.split_mongo, self.old_mongo, self.draft_mongo, self.loc_mapper)
        self.course_location = None
        self.create_source_course()

    def tearDown(self):
        dbref = self.loc_mapper.db
        dbref.drop_collection(self.loc_mapper.location_map)
        split_db = self.split_mongo.db
        split_db.drop_collection(self.split_mongo.db_connection.course_index)
        split_db.drop_collection(self.split_mongo.db_connection.structures)
        split_db.drop_collection(self.split_mongo.db_connection.definitions)
        # old_mongo doesn't give a db attr, but all of the dbs are the same
        dbref.drop_collection(self.old_mongo.collection)

        dbref.connection.close()

        super(TestMigration, self).tearDown()

    def _create_and_get_item(self, store, location, data, metadata, runtime=None):
        store.create_and_save_xmodule(location, data, metadata, runtime)
        return store.get_item(location)

    def create_source_course(self):
        """
        A course testing all of the conversion mechanisms:
        * some inheritable settings
        * sequences w/ draft and live intermixed children to ensure all get to the draft but
        only the live ones get to published. Some are only draft, some are both, some are only live.
        * about, static_tab, and conditional documents
        """
        location = Location('i4x', 'test_org', 'test_course', 'course', 'runid')
        self.course_location = location
        date_proxy = Date()
        metadata = {
            'start': date_proxy.to_json(datetime.datetime(2000, 3, 13, 4)),
            'display_name': 'Migration test course',
        }
        data = {
            'wiki_slug': 'test_course_slug'
        }
        course_root = self._create_and_get_item(self.old_mongo, location, data, metadata)
        runtime = course_root.runtime
        # chapters
        location = location.replace(category='chapter', name=uuid.uuid4().hex)
        chapter1 = self._create_and_get_item(self.old_mongo, location, {}, {'display_name': 'Chapter 1'}, runtime)
        course_root.children.append(chapter1.location.url())
        location = location.replace(category='chapter', name=uuid.uuid4().hex)
        chapter2 = self._create_and_get_item(self.old_mongo, location, {}, {'display_name': 'Chapter 2'}, runtime)
        course_root.children.append(chapter2.location.url())
        self.old_mongo.update_children(course_root.location, course_root.children)
        # vertical in live only
        location = location.replace(category='vertical', name=uuid.uuid4().hex)
        live_vert = self._create_and_get_item(self.old_mongo, location, {}, {'display_name': 'Live vertical'}, runtime)
        chapter1.children.append(live_vert.location.url())
        self.create_random_units(self.old_mongo, live_vert)
        # vertical in both live and draft
        location = location.replace(category='vertical', name=uuid.uuid4().hex)
        both_vert = self._create_and_get_item(
            self.old_mongo, location, {}, {'display_name': 'Both vertical'}, runtime
        )
        draft_both = self._create_and_get_item(
            self.draft_mongo, location, {}, {'display_name': 'Both vertical renamed'}, runtime
        )
        chapter1.children.append(both_vert.location.url())
        self.create_random_units(self.old_mongo, both_vert, self.draft_mongo, draft_both)
        # vertical in draft only (x2)
        location = location.replace(category='vertical', name=uuid.uuid4().hex)
        draft_vert = self._create_and_get_item(
            self.draft_mongo,
            location, {}, {'display_name': 'Draft vertical'}, runtime)
        chapter1.children.append(draft_vert.location.url())
#.........这里部分代码省略.........
开发者ID:DavidGrahamFL,项目名称:edx-platform,代码行数:101,代码来源:test_split_migrator.py


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