Commit e047a30b by cahrens

Support only at xblock level.

parent 1ee87c88
......@@ -27,7 +27,7 @@ from opaque_keys.edx.keys import UsageKey
from student.auth import has_course_author_access
from django.utils.translation import ugettext as _
from xblock_django.models import XBlockDisableConfig
from xblock_django.models import XBlockConfig, XBlockConfigFlag
__all__ = [
'container_handler',
......@@ -52,12 +52,15 @@ CONTAINER_TEMPLATES = [
]
def _advanced_component_types():
def _advanced_component_types(show_unsupported):
"""
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]
if XBlockConfigFlag.is_enabled():
authorable_xblock_types = [block.name for block in XBlockConfig.authorable_xblocks(show_unsupported)]
return [c_type for c_type in ADVANCED_COMPONENT_TYPES if c_type in authorable_xblock_types]
else:
return [c_type for c_type in ADVANCED_COMPONENT_TYPES]
def _load_mixed_class(category):
......@@ -221,9 +224,10 @@ def get_component_templates(courselike, library=False):
)
)
# Add any advanced problem types
# Add any advanced problem types. Note that this are different xblocks being stored as Advanced Problems.
if category == 'problem':
for advanced_problem_type in ADVANCED_PROBLEM_TYPES:
# TODO: check the state of these also, since they are actually xblocks?
component = advanced_problem_type['component']
boilerplate_name = advanced_problem_type['boilerplate_name']
try:
......@@ -252,7 +256,8 @@ def get_component_templates(courselike, library=False):
# enabled for the course.
course_advanced_keys = courselike.advanced_modules
advanced_component_templates = {"type": "advanced", "templates": [], "display_name": _("Advanced")}
advanced_component_types = _advanced_component_types()
# TODO: pass in the value for this course of whether or not unsupported xblocks can be displayed.
advanced_component_types = _advanced_component_types(False)
# Set component types according to course policy file
if isinstance(course_advanced_keys, list):
for category in course_advanced_keys:
......
......@@ -99,6 +99,7 @@ from xmodule.modulestore import EdxJSONEncoder
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError
from xmodule.tabs import CourseTab, CourseTabList, InvalidTabsException
from xblock_django.models import XBlockConfig, XBlockConfigFlag
log = logging.getLogger(__name__)
......@@ -599,7 +600,10 @@ def course_index(request, course_key):
except (ItemNotFoundError, CourseActionStateItemNotFoundError):
current_action = None
deprecated_blocks_info = _deprecated_blocks_info(course_module, settings.DEPRECATED_BLOCK_TYPES)
# TODO: all check that the feature flag is enabled at all!
deprecated_block_names = [block.name for block in XBlockConfig.deprecated_xblocks()] \
if XBlockConfigFlag.is_enabled() else []
deprecated_blocks_info = _deprecated_blocks_info(course_module, deprecated_block_names)
return render_to_response('course_outline.html', {
'context_course': course_module,
......
......@@ -1121,6 +1121,7 @@ XBLOCK_SETTINGS = {
# 2. List all instances of that XBlock on the top of the course outline page asking
# course authors to delete or replace the instances.
DEPRECATED_BLOCK_TYPES = [
'done',
'peergrading',
'combinedopenended',
'graphical_slider_tool',
......
......@@ -4,6 +4,13 @@ Django admin dashboard configuration.
from django.contrib import admin
from config_models.admin import ConfigurationModelAdmin
from xblock_django.models import XBlockDisableConfig
from xblock_django.models import XBlockDisableConfig, XBlockConfig, XBlockConfigFlag
class XBlockConfigAdmin(admin.ModelAdmin):
"""Admin for XBlock Configuration"""
list_display = ('name', 'support_level', 'deprecated')
admin.site.register(XBlockDisableConfig, ConfigurationModelAdmin)
admin.site.register(XBlockConfigFlag, ConfigurationModelAdmin)
admin.site.register(XBlockConfig, XBlockConfigAdmin)
......@@ -3,11 +3,10 @@ Models.
"""
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.db.models import TextField
from config_models.models import ConfigurationModel
from django.db import models
class XBlockDisableConfig(ConfigurationModel):
......@@ -30,45 +29,104 @@ class XBlockDisableConfig(ConfigurationModel):
)
)
@classmethod
def is_block_type_disabled(cls, block_type):
""" Return True if block_type is disabled. """
# @classmethod
# def is_block_type_disabled(cls, block_type):
# """ Return True if block_type is disabled. """
#
# config = cls.current()
# if not config.enabled:
# return False
#
# return block_type in config.disabled_blocks.split()
# @classmethod
# def disabled_block_types(cls):
# """ Return list of disabled xblock types. """
#
# config = cls.current()
# if not config.enabled:
# return ()
#
# return config.disabled_blocks.split()
# @classmethod
# def disabled_create_block_types(cls):
# """ Return list of deprecated XBlock types. Merges types in settings file and field. """
#
# config = cls.current()
# xblock_types = config.disabled_create_blocks.split() if config.enabled else []
#
# # Merge settings list with one in the admin config;
# if hasattr(settings, 'DEPRECATED_ADVANCED_COMPONENT_TYPES'):
# xblock_types.extend(
# xblock_type for xblock_type in settings.DEPRECATED_ADVANCED_COMPONENT_TYPES
# if xblock_type not in xblock_types
# )
#
# return xblock_types
#
# def __unicode__(self):
# config = XBlockDisableConfig.current()
# return u"Disabled xblocks = {disabled_xblocks}\nDeprecated xblocks = {disabled_create_block_types}".format(
# disabled_xblocks=config.disabled_blocks,
# disabled_create_block_types=config.disabled_create_block_types
# )
class XBlockConfigFlag(ConfigurationModel):
"""
Enables site-wide configuration for xblock support state.
"""
class Meta(object):
app_label = "xblock_django"
class XBlockConfig(models.Model):
"""
Configuration for a specific xblock. Currently used for support state.
"""
FULL_SUPPORT = 'fs'
PROVISIONAL_SUPPORT = 'ps'
UNSUPPORTED_OPT_IN = 'ua'
UNSUPPORTED_NO_OPT_IN = 'ud'
DISABLED = 'da'
SUPPORT_CHOICES = (
(FULL_SUPPORT, _('Fully Supported')),
(PROVISIONAL_SUPPORT, _('Provisionally Supported')),
(UNSUPPORTED_OPT_IN, _('Unsupported (Opt-in allowed)')),
(UNSUPPORTED_NO_OPT_IN, _('Unsupported (Opt-in disallowed)')),
(DISABLED, _('Disabled')),
)
config = cls.current()
if not config.enabled:
return False
name = models.CharField(max_length=255, primary_key=True)
support_level = models.CharField(max_length=2, choices=SUPPORT_CHOICES, default=UNSUPPORTED_NO_OPT_IN)
deprecated = models.BooleanField(default=False, verbose_name=_('show deprecation messaging in Studio'))
return block_type in config.disabled_blocks.split()
class Meta(object):
app_label = "xblock_django"
@classmethod
def disabled_block_types(cls):
""" Return list of disabled xblock types. """
def deprecated_xblocks(cls):
""" Return list of deprecated XBlock types. """
config = cls.current()
if not config.enabled:
return ()
return cls.objects.filter(deprecated=True)
@classmethod
def disabled_xblocks(cls):
""" Return list of xblocks that should not render. """
return config.disabled_blocks.split()
return cls.objects.filter(support_level=cls.DISABLED)
@classmethod
def disabled_create_block_types(cls):
""" Return list of deprecated XBlock types. Merges types in settings file and field. """
config = cls.current()
xblock_types = config.disabled_create_blocks.split() if config.enabled else []
# Merge settings list with one in the admin config;
if hasattr(settings, 'DEPRECATED_ADVANCED_COMPONENT_TYPES'):
xblock_types.extend(
xblock_type for xblock_type in settings.DEPRECATED_ADVANCED_COMPONENT_TYPES
if xblock_type not in xblock_types
)
return xblock_types
def __unicode__(self):
config = XBlockDisableConfig.current()
return u"Disabled xblocks = {disabled_xblocks}\nDeprecated xblocks = {disabled_create_block_types}".format(
disabled_xblocks=config.disabled_blocks,
disabled_create_block_types=config.disabled_create_block_types
)
def authorable_xblocks(cls, limited_support_opt_in=False):
""" Return list of xblocks that can be created in Studio """
blocks = cls.objects.exclude(support_level=cls.DISABLED).exclude(support_level=cls.UNSUPPORTED_NO_OPT_IN)
if not limited_support_opt_in:
blocks.exclude(support_level=cls.UNSUPPORTED_OPT_IN)
return blocks
# TODO: should there be a unicode method?
......@@ -49,9 +49,9 @@ except ImportError:
HAS_USER_SERVICE = False
try:
from xblock_django.models import XBlockDisableConfig
from xblock_django.models import XBlockConfigFlag, XBlockConfig
except ImportError:
XBlockDisableConfig = None
XBlockConfigFlag = None
log = logging.getLogger(__name__)
ASSET_IGNORE_REGEX = getattr(settings, "ASSET_IGNORE_REGEX", r"(^\._.*$)|(^\.DS_Store$)|(^.*~$)")
......@@ -188,8 +188,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 XBlockConfigFlag and XBlockConfigFlag.is_enabled():
disabled_xblock_types = [block.name for block in XBlockConfig.disabled_xblocks()]
else:
disabled_xblock_types = ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment