Exemplo n.º 1
0
 def _enable_xblock_disable_config(self, enabled):
     """ Enable or disable xblocks disable. """
     config = XBlockDisableConfig.current()
     config.enabled = enabled
     config.disabled_blocks = "\n".join(('combinedopenended', 'peergrading'))
     config.save()
     cache.clear()
Exemplo n.º 2
0
    def test_deprecated_blocks_file_and_config(self):
        """
        Tests that deprecated types defined in both settings and config model are read.
        """
        XBlockDisableConfig.objects.create(
            disabled_create_blocks='annotatable', enabled=True)

        self.assertEqual(XBlockDisableConfig.disabled_create_block_types(),
                         ['annotatable', 'poll', 'survey'])
Exemplo n.º 3
0
    def test_deprecated_blocks_splitting(self, xblocks, expected_result):
        """
        Tests that it correctly splits the xblocks defined in field.
        """
        XBlockDisableConfig.objects.create(disabled_create_blocks=xblocks,
                                           enabled=True)

        self.assertEqual(XBlockDisableConfig.disabled_create_block_types(),
                         expected_result)
Exemplo n.º 4
0
def _advanced_component_types():
    """
    Return advanced component types which can be created.
    """
    disabled_create_block_types = XBlockDisableConfig.disabled_create_block_types(
    )
    return [
        c_type for c_type in ADVANCED_COMPONENT_TYPES
        if c_type not in disabled_create_block_types
    ]
Exemplo n.º 5
0
def create_modulestore_instance(
    engine,
    content_store,
    doc_store_config,
    options,
    i18n_service=None,
    fs_service=None,
    user_service=None,
    signal_handler=None,
):
    """
    This will return a new instance of a modulestore given an engine and options
    """
    class_ = load_function(engine)

    _options = {}
    _options.update(options)

    FUNCTION_KEYS = ['render_template']
    for key in FUNCTION_KEYS:
        if key in _options and isinstance(_options[key], basestring):
            _options[key] = load_function(_options[key])

    if HAS_REQUEST_CACHE:
        request_cache = RequestCache.get_request_cache()
    else:
        request_cache = None

    try:
        metadata_inheritance_cache = caches['mongo_metadata_inheritance']
    except InvalidCacheBackendError:
        metadata_inheritance_cache = caches['default']

    if issubclass(class_, MixedModuleStore):
        _options['create_modulestore_instance'] = create_modulestore_instance

    if issubclass(class_, BranchSettingMixin):
        _options['branch_setting_func'] = _get_modulestore_branch_setting

    if HAS_USER_SERVICE and not user_service:
        xb_user_service = DjangoXBlockUserService(get_current_user())
    else:
        xb_user_service = None

    if 'read_preference' in doc_store_config:
        doc_store_config['read_preference'] = getattr(
            ReadPreference, doc_store_config['read_preference'])

    if XBlockDisableConfig and settings.FEATURES.get(
            'ENABLE_DISABLING_XBLOCK_TYPES', False):
        disabled_xblock_types = XBlockDisableConfig.disabled_block_types()
    else:
        disabled_xblock_types = ()

    xblock_field_data_wrappers = [
        load_function(path) for path in settings.XBLOCK_FIELD_DATA_WRAPPERS
    ]

    return class_(
        contentstore=content_store,
        metadata_inheritance_cache_subsystem=metadata_inheritance_cache,
        request_cache=request_cache,
        xblock_mixins=getattr(settings, 'XBLOCK_MIXINS', ()),
        xblock_select=getattr(settings, 'XBLOCK_SELECT_FUNCTION', None),
        xblock_field_data_wrappers=xblock_field_data_wrappers,
        disabled_xblock_types=disabled_xblock_types,
        doc_store_config=doc_store_config,
        i18n_service=i18n_service or ModuleI18nService(),
        fs_service=fs_service or xblock.reference.plugins.FSService(),
        user_service=user_service or xb_user_service,
        signal_handler=signal_handler or SignalHandler(class_),
        **_options)
Exemplo n.º 6
0
def create_modulestore_instance(
        engine,
        content_store,
        doc_store_config,
        options,
        i18n_service=None,
        fs_service=None,
        user_service=None,
        signal_handler=None,
):
    """
    This will return a new instance of a modulestore given an engine and options
    """
    class_ = load_function(engine)

    _options = {}
    _options.update(options)

    FUNCTION_KEYS = ['render_template']
    for key in FUNCTION_KEYS:
        if key in _options and isinstance(_options[key], basestring):
            _options[key] = load_function(_options[key])

    if HAS_REQUEST_CACHE:
        request_cache = RequestCache.get_request_cache()
    else:
        request_cache = None

    try:
        metadata_inheritance_cache = caches['mongo_metadata_inheritance']
    except InvalidCacheBackendError:
        metadata_inheritance_cache = caches['default']

    if issubclass(class_, MixedModuleStore):
        _options['create_modulestore_instance'] = create_modulestore_instance

    if issubclass(class_, BranchSettingMixin):
        _options['branch_setting_func'] = _get_modulestore_branch_setting

    if HAS_USER_SERVICE and not user_service:
        xb_user_service = DjangoXBlockUserService(get_current_user())
    else:
        xb_user_service = None

    if 'read_preference' in doc_store_config:
        doc_store_config['read_preference'] = getattr(ReadPreference, doc_store_config['read_preference'])

    if XBlockDisableConfig and settings.FEATURES.get('ENABLE_DISABLING_XBLOCK_TYPES', False):
        disabled_xblock_types = XBlockDisableConfig.disabled_block_types()
    else:
        disabled_xblock_types = ()

    return class_(
        contentstore=content_store,
        metadata_inheritance_cache_subsystem=metadata_inheritance_cache,
        request_cache=request_cache,
        xblock_mixins=getattr(settings, 'XBLOCK_MIXINS', ()),
        xblock_select=getattr(settings, 'XBLOCK_SELECT_FUNCTION', None),
        disabled_xblock_types=disabled_xblock_types,
        doc_store_config=doc_store_config,
        i18n_service=i18n_service or ModuleI18nService(),
        fs_service=fs_service or xblock.reference.plugins.FSService(),
        user_service=user_service or xb_user_service,
        signal_handler=signal_handler or SignalHandler(class_),
        **_options
    )
Exemplo n.º 7
0
 def is_enabled(cls, course, user=None):  # pylint: disable=unused-argument
     if XBlockDisableConfig.is_block_type_disabled('combinedopenended'):
         return False
     if not super(PeerGradingTab, cls).is_enabled(course, user=user):
         return False
     return "combinedopenended" in course.advanced_modules
Exemplo n.º 8
0
 def is_enabled(cls, course, user=None):  # pylint: disable=unused-argument
     if XBlockDisableConfig.is_block_type_disabled('combinedopenended'):
         return False
     if user and not has_access(user, 'staff', course, course.id):
         return False
     return "combinedopenended" in course.advanced_modules
Exemplo n.º 9
0
def _advanced_component_types():
    """
    Return advanced component types which can be created.
    """
    disabled_create_block_types = XBlockDisableConfig.disabled_create_block_types()
    return [c_type for c_type in ADVANCED_COMPONENT_TYPES if c_type not in disabled_create_block_types]
Exemplo n.º 10
0
 def is_enabled(cls, course, user=None):
     if XBlockDisableConfig.is_block_type_disabled('combinedopenended'):
         return False
     if user and not has_access(user, 'staff', course, course.id):
         return False
     return "combinedopenended" in course.advanced_modules
Exemplo n.º 11
0
 def is_enabled(cls, course, user=None):
     if XBlockDisableConfig.is_block_type_disabled('combinedopenended'):
         return False
     if not super(OpenEndedGradingTab, cls).is_enabled(course, user=user):
         return False
     return "combinedopenended" in course.advanced_modules
Exemplo n.º 12
0
 def test_deprecated_blocks_file(self):
     """
     Tests that deprecated modules contain entries from settings file DEPRECATED_ADVANCED_COMPONENT_TYPES
     """
     self.assertEqual(XBlockDisableConfig.disabled_create_block_types(),
                      ['poll', 'survey'])
Exemplo n.º 13
0
 def is_enabled(cls, course, user=None):
     if XBlockDisableConfig.is_block_type_disabled('combinedopenended'):
         return False
     if not super(OpenEndedGradingTab, cls).is_enabled(course, user=user):
         return False
     return "combinedopenended" in course.advanced_modules
Exemplo n.º 14
0
 def is_enabled(cls, course, user=None):  # pylint: disable=unused-argument
     if XBlockDisableConfig.is_block_type_disabled('combinedopenended'):
         return False
     if not super(PeerGradingTab, cls).is_enabled(course, user=user):
         return False
     return "combinedopenended" in course.advanced_modules