Commit 9f09cb85 by cahrens

Updates

parent 99dccf98
...@@ -5,8 +5,10 @@ Django admin dashboard configuration. ...@@ -5,8 +5,10 @@ Django admin dashboard configuration.
from django.contrib import admin from django.contrib import admin
from config_models.admin import ConfigurationModelAdmin from config_models.admin import ConfigurationModelAdmin
from xblock_django.models import XBlockDisableConfig, XBlockConfig, XBlockConfigFlag from xblock_django.models import XBlockDisableConfig, XBlockConfig, XBlockConfigFlag
from simple_history.admin import SimpleHistoryAdmin
#class XBlockConfigAdmin(SimpleHistoryAdmin):
class XBlockConfigAdmin(admin.ModelAdmin): class XBlockConfigAdmin(admin.ModelAdmin):
"""Admin for XBlock Configuration""" """Admin for XBlock Configuration"""
list_display = ('name', 'template', 'support_level', 'deprecated') list_display = ('name', 'template', 'support_level', 'deprecated')
......
...@@ -8,6 +8,8 @@ from django.db.models import TextField ...@@ -8,6 +8,8 @@ from django.db.models import TextField
from config_models.models import ConfigurationModel from config_models.models import ConfigurationModel
from django.db import models from django.db import models
from simple_history.models import HistoricalRecords
class XBlockDisableConfig(ConfigurationModel): class XBlockDisableConfig(ConfigurationModel):
""" """
...@@ -73,6 +75,7 @@ class XBlockDisableConfig(ConfigurationModel): ...@@ -73,6 +75,7 @@ class XBlockDisableConfig(ConfigurationModel):
# ) # )
class XBlockConfigFlag(ConfigurationModel): class XBlockConfigFlag(ConfigurationModel):
""" """
Enables site-wide configuration for xblock support state. Enables site-wide configuration for xblock support state.
...@@ -100,6 +103,9 @@ class XBlockConfig(models.Model): ...@@ -100,6 +103,9 @@ class XBlockConfig(models.Model):
(DISABLED, _('Disabled')), (DISABLED, _('Disabled')),
) )
# for archiving
# history = HistoricalRecords()
name = models.CharField(max_length=255, null=False) name = models.CharField(max_length=255, null=False)
template = models.CharField(max_length=255, blank=True, default='') template = models.CharField(max_length=255, blank=True, default='')
support_level = models.CharField(max_length=2, choices=SUPPORT_CHOICES, default=UNSUPPORTED_NO_OPT_IN) support_level = models.CharField(max_length=2, choices=SUPPORT_CHOICES, default=UNSUPPORTED_NO_OPT_IN)
...@@ -109,37 +115,46 @@ class XBlockConfig(models.Model): ...@@ -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.") 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): class Meta(object):
app_label = "xblock_django" app_label = "xblock_django"
unique_together = ("name", "template") unique_together = ("name", "template")
@classmethod @classmethod
def deprecated_xblocks(cls): def deprecated_xblocks(cls):
""" Return list of deprecated XBlock types. """ """ Return the QuerySet of deprecated XBlock types. """
return cls.objects.filter(deprecated=True) return cls.objects.filter(deprecated=True)
@classmethod @classmethod
def disabled_xblocks(cls): 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) return cls.objects.filter(support_level=cls.DISABLED)
@classmethod @classmethod
def authorable_xblocks(cls, limited_support_opt_in=False, name=None): 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) blocks = cls.objects.exclude(support_level=cls.DISABLED).exclude(support_level=cls.UNSUPPORTED_NO_OPT_IN)
if not limited_support_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: if name:
blocks = blocks.filter(name=name) blocks = blocks.filter(name=name)
return blocks return blocks
def __unicode__(self):
# TODO: should there be a unicode method? return (
"[XBlockConfig] '{}': template='{}', support level='{}', deprecated={}"
).format(self.name, self.template, self.support_level, self.deprecated)
...@@ -5,54 +5,165 @@ import ddt ...@@ -5,54 +5,165 @@ import ddt
from mock import patch from mock import patch
from django.test import TestCase from django.test import TestCase
from xblock_django.models import XBlockDisableConfig from xblock_django.models import XBlockDisableConfig, XBlockConfig
@ddt.ddt # @ddt.ddt
class XBlockDisableConfigTestCase(TestCase): # class XBlockDisableConfigTestCase(TestCase):
""" # """
Tests for the DjangoXBlockUserService. # Tests for the DjangoXBlockUserService.
""" # """
def setUp(self): # def setUp(self):
super(XBlockDisableConfigTestCase, self).setUp() # 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( class XBlockConfigTestCase(TestCase):
disabled_blocks='', enabled=True
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
) )
@ddt.data( XBlockConfig.objects.create(
('poll', ['poll']), name="survey",
('poll survey annotatable textannotation', ['poll', 'survey', 'annotatable', 'textannotation']), support_level=XBlockConfig.DISABLED,
('', []) deprecated=True
) )
@ddt.unpack
def test_deprecated_blocks_splitting(self, xblocks, expected_result): XBlockConfig.objects.create(
""" name="done",
Tests that it correctly splits the xblocks defined in field. support_level=XBlockConfig.FULL_SUPPORT
""" )
XBlockDisableConfig.objects.create(
disabled_create_blocks=xblocks, enabled=True 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
) )
self.assertEqual( XBlockConfig.objects.create(
XBlockDisableConfig.disabled_create_block_types(), expected_result name="survey",
support_level=XBlockConfig.DISABLED,
deprecated=True
) )
@patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ['poll', 'survey']) XBlockConfig.objects.create(
def test_deprecated_blocks_file(self): name="annotatable",
""" support_level=XBlockConfig.DISABLED,
Tests that deprecated modules contain entries from settings file DEPRECATED_ADVANCED_COMPONENT_TYPES deprecated=False
""" )
self.assertEqual(XBlockDisableConfig.disabled_create_block_types(), ['poll', 'survey'])
XBlockConfig.objects.create(
name="done",
support_level=XBlockConfig.FULL_SUPPORT
)
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
)
@patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', ['poll', 'survey']) XBlockConfig.objects.create(
def test_deprecated_blocks_file_and_config(self): name="problem",
""" support_level=XBlockConfig.FULL_SUPPORT,
Tests that deprecated types defined in both settings and config model are read. template="multiple_choice"
"""
XBlockDisableConfig.objects.create(
disabled_create_blocks='annotatable', enabled=True
) )
self.assertEqual(XBlockDisableConfig.disabled_create_block_types(), ['annotatable', '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
)
XBlockConfig.objects.create(
name="poll",
support_level=XBlockConfig.UNSUPPORTED_NO_OPT_IN,
deprecated=True
)
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