Commit 9f09cb85 by cahrens

Updates

parent 99dccf98
......@@ -5,8 +5,10 @@ Django admin dashboard configuration.
from django.contrib import admin
from config_models.admin import ConfigurationModelAdmin
from xblock_django.models import XBlockDisableConfig, XBlockConfig, XBlockConfigFlag
from simple_history.admin import SimpleHistoryAdmin
#class XBlockConfigAdmin(SimpleHistoryAdmin):
class XBlockConfigAdmin(admin.ModelAdmin):
"""Admin for XBlock Configuration"""
list_display = ('name', 'template', 'support_level', 'deprecated')
......
......@@ -8,6 +8,8 @@ from django.db.models import TextField
from config_models.models import ConfigurationModel
from django.db import models
from simple_history.models import HistoricalRecords
class XBlockDisableConfig(ConfigurationModel):
"""
......@@ -73,6 +75,7 @@ class XBlockDisableConfig(ConfigurationModel):
# )
class XBlockConfigFlag(ConfigurationModel):
"""
Enables site-wide configuration for xblock support state.
......@@ -100,6 +103,9 @@ class XBlockConfig(models.Model):
(DISABLED, _('Disabled')),
)
# for archiving
# history = HistoricalRecords()
name = models.CharField(max_length=255, null=False)
template = models.CharField(max_length=255, blank=True, default='')
support_level = models.CharField(max_length=2, choices=SUPPORT_CHOICES, default=UNSUPPORTED_NO_OPT_IN)
......@@ -109,37 +115,46 @@ class XBlockConfig(models.Model):
help_text=_("Only xblocks listed in a course's Advanced Module List can be flagged as deprecated. Note that deprecation is by xblock name, and is not specific to template.")
)
# TODO: error if deprecated is set on core xblock types?
# TODO: error if disabled is set on core xblock types (or something with a template)?
class Meta(object):
app_label = "xblock_django"
unique_together = ("name", "template")
@classmethod
def deprecated_xblocks(cls):
""" Return list of deprecated XBlock types. """
""" Return the QuerySet of deprecated XBlock types. """
return cls.objects.filter(deprecated=True)
@classmethod
def disabled_xblocks(cls):
""" Return list of xblocks that should not render. """
""" Return the QuerySet of XBlocks that are disabled. """
return cls.objects.filter(support_level=cls.DISABLED)
@classmethod
def authorable_xblocks(cls, limited_support_opt_in=False, name=None):
""" Return list of xblocks that can be created in Studio """
"""
Return the QuerySet of XBlocks that can be created in Studio. Note that this method
looks only at `support_level` and does not take into account `deprecated`.
Arguments:
limited_support_opt_in (bool): If `True`, XBlocks with limited support will be included.
Default value is `False`.
name (str): If provided, filters the returned XBlocks to those with the provided name. This is
useful for XBlocks with lots of template types.
Returns:
QuerySet: Authorable XBlocks, taking into account `support_level` and `name` (if specified).
"""
blocks = cls.objects.exclude(support_level=cls.DISABLED).exclude(support_level=cls.UNSUPPORTED_NO_OPT_IN)
if not limited_support_opt_in:
blocks = blocks.exclude(support_level=cls.UNSUPPORTED_OPT_IN)
blocks = blocks.exclude(support_level=cls.UNSUPPORTED_OPT_IN).exclude(support_level=cls.PROVISIONAL_SUPPORT)
if name:
blocks = blocks.filter(name=name)
return blocks
# TODO: should there be a unicode method?
def __unicode__(self):
return (
"[XBlockConfig] '{}': template='{}', support level='{}', deprecated={}"
).format(self.name, self.template, self.support_level, self.deprecated)
......@@ -5,54 +5,165 @@ import ddt
from mock import patch
from django.test import TestCase
from xblock_django.models import XBlockDisableConfig
from xblock_django.models import XBlockDisableConfig, XBlockConfig
@ddt.ddt
class XBlockDisableConfigTestCase(TestCase):
"""
Tests for the DjangoXBlockUserService.
"""
def setUp(self):
super(XBlockDisableConfigTestCase, self).setUp()
# @ddt.ddt
# class XBlockDisableConfigTestCase(TestCase):
# """
# Tests for the DjangoXBlockUserService.
# """
# def setUp(self):
# super(XBlockDisableConfigTestCase, self).setUp()
#
# # Initialize the deprecated modules settings with empty list
# XBlockDisableConfig.objects.create(
# disabled_blocks='', enabled=True
# )
#
# @ddt.data(
# ('poll', ['poll']),
# ('poll survey annotatable textannotation', ['poll', 'survey', 'annotatable', 'textannotation']),
# ('', [])
# )
# @ddt.unpack
# 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
# )
#
# @patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ['poll', 'survey'])
# 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'])
#
# @patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ['poll', 'survey'])
# 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'])
# Initialize the deprecated modules settings with empty list
XBlockDisableConfig.objects.create(
disabled_blocks='', enabled=True
class XBlockConfigTestCase(TestCase):
def tearDown(self):
super(XBlockConfigTestCase, self).tearDown()
XBlockConfig.objects.all().delete()
def test_deprecated_blocks(self):
XBlockConfig.objects.create(
name="poll",
support_level=XBlockConfig.UNSUPPORTED_NO_OPT_IN,
deprecated=True
)
XBlockConfig.objects.create(
name="survey",
support_level=XBlockConfig.DISABLED,
deprecated=True
)
XBlockConfig.objects.create(
name="done",
support_level=XBlockConfig.FULL_SUPPORT
)
deprecated_xblock_names = [block.name for block in XBlockConfig.deprecated_xblocks()]
self.assertEqual(["poll", "survey"], deprecated_xblock_names)
def test_disabled_blocks(self):
XBlockConfig.objects.create(
name="poll",
support_level=XBlockConfig.UNSUPPORTED_NO_OPT_IN,
deprecated=True
)
XBlockConfig.objects.create(
name="survey",
support_level=XBlockConfig.DISABLED,
deprecated=True
)
XBlockConfig.objects.create(
name="annotatable",
support_level=XBlockConfig.DISABLED,
deprecated=False
)
XBlockConfig.objects.create(
name="done",
support_level=XBlockConfig.FULL_SUPPORT
)
@ddt.data(
('poll', ['poll']),
('poll survey annotatable textannotation', ['poll', 'survey', 'annotatable', 'textannotation']),
('', [])
)
@ddt.unpack
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
disabled_xblock_names = [block.name for block in XBlockConfig.disabled_xblocks()]
self.assertEqual(["survey", "annotatable"], disabled_xblock_names)
def test_authorable_blocks(self):
XBlockConfig.objects.create(
name="problem",
support_level=XBlockConfig.FULL_SUPPORT
)
self.assertEqual(
XBlockDisableConfig.disabled_create_block_types(), expected_result
XBlockConfig.objects.create(
name="problem",
support_level=XBlockConfig.FULL_SUPPORT,
template="multiple_choice"
)
@patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ['poll', 'survey'])
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'])
XBlockConfig.objects.create(
name="html",
support_level=XBlockConfig.PROVISIONAL_SUPPORT,
template="zoom"
)
XBlockConfig.objects.create(
name="split_module",
support_level=XBlockConfig.UNSUPPORTED_OPT_IN,
deprecated=True
)
@patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ['poll', 'survey'])
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
XBlockConfig.objects.create(
name="poll",
support_level=XBlockConfig.UNSUPPORTED_NO_OPT_IN,
deprecated=True
)
self.assertEqual(XBlockDisableConfig.disabled_create_block_types(), ['annotatable', 'poll', 'survey'])
XBlockConfig.objects.create(
name="survey",
support_level=XBlockConfig.DISABLED,
)
authorable_xblock_names = [block.name for block in XBlockConfig.authorable_xblocks()]
self.assertEqual(["problem", "problem"], authorable_xblock_names)
authorable_xblock_names = [block.name for block in XBlockConfig.authorable_xblocks(limited_support_opt_in=True)]
self.assertEqual(["problem", "problem", "html", "split_module"], authorable_xblock_names)
authorable_xblocks = XBlockConfig.authorable_xblocks(name="problem", limited_support_opt_in=True)
self.assertEqual(2, len(authorable_xblocks))
self.assertEqual("problem", authorable_xblocks[0].name)
self.assertEqual("", authorable_xblocks[0].template)
self.assertEqual("problem", authorable_xblocks[1].name)
self.assertEqual("multiple_choice", authorable_xblocks[1].template)
authorable_xblocks = XBlockConfig.authorable_xblocks(name="html", limited_support_opt_in=True)
self.assertEqual(1, len(authorable_xblocks))
self.assertEqual("html", authorable_xblocks[0].name)
self.assertEqual("zoom", authorable_xblocks[0].template)
authorable_xblocks = XBlockConfig.authorable_xblocks(name="video")
self.assertEqual(0, len(authorable_xblocks))
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