Switch disabling of XBlocks to XBlockConfiguration.

Also allows dynamic updates.
TNL-4668
This commit is contained in:
cahrens
2016-06-24 16:25:36 -04:00
parent 39c2abdf28
commit 8980d1ab2d
5 changed files with 57 additions and 21 deletions

View File

@@ -19,6 +19,7 @@ from django.conf import settings
if not settings.configured:
settings.configure()
from django.db.models.signals import post_save
from django.core.cache import caches, InvalidCacheBackendError
import django.dispatch
import django.utils
@@ -49,9 +50,11 @@ except ImportError:
HAS_USER_SERVICE = False
try:
from xblock_django.models import XBlockDisableConfig
from xblock_django.api import disabled_xblocks
from xblock_django.models import XBlockConfiguration
except ImportError:
XBlockDisableConfig = None
disabled_xblocks = None
XBlockConfiguration = None
log = logging.getLogger(__name__)
ASSET_IGNORE_REGEX = getattr(settings, "ASSET_IGNORE_REGEX", r"(^\._.*$)|(^\.DS_Store$)|(^.*~$)")
@@ -188,8 +191,8 @@ def create_modulestore_instance(
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()
if disabled_xblocks:
disabled_xblock_types = [block.name for block in disabled_xblocks()]
else:
disabled_xblock_types = ()
@@ -252,6 +255,17 @@ def clear_existing_modulestores():
_MIXED_MODULESTORE = None
if XBlockConfiguration and disabled_xblocks:
@django.dispatch.receiver(post_save, sender=XBlockConfiguration)
def reset_disabled_xblocks(sender, instance, **kwargs): # pylint: disable=unused-argument
"""
If XBlockConfiguation and disabled_xblocks are available, register a signal handler
to update disabled_xblocks on model changes.
"""
disabled_xblock_types = [block.name for block in disabled_xblocks()]
modulestore().disabled_xblock_types = disabled_xblock_types
class ModuleI18nService(object):
"""
Implement the XBlock runtime "i18n" service.

View File

@@ -185,6 +185,25 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
self.mappings[course_key] = store
self.modulestores.append(store)
@property
def disabled_xblock_types(self):
"""
Returns the list of disabled xblock types.
"""
return None if not hasattr(self, "_disabled_xblock_types") else self._disabled_xblock_types
@disabled_xblock_types.setter
def disabled_xblock_types(self, value):
"""
Sets the list of disabled xblock types, and propagates down
to child modulestores if available.
"""
self._disabled_xblock_types = value # pylint: disable=attribute-defined-outside-init
if hasattr(self, 'modulestores'):
for store in self.modulestores:
store.disabled_xblock_types = value
def _clean_locator_for_mapping(self, locator):
"""
In order for mapping to work, the locator must be minimal--no version, no branch--