Commit 603a97fa by Han Su Kim

Merge pull request #2880 from edx/cale/fix-crazy-items-error

Cale/fix crazy items error
parents d2c147bf 0a79b30e
...@@ -23,7 +23,6 @@ from xblock.exceptions import NoSuchHandlerError ...@@ -23,7 +23,6 @@ from xblock.exceptions import NoSuchHandlerError
from xblock.fields import Scope from xblock.fields import Scope
from xblock.plugin import PluginMissingError from xblock.plugin import PluginMissingError
from xblock.runtime import Mixologist from xblock.runtime import Mixologist
from xmodule.x_module import prefer_xmodules
from lms.lib.xblock.runtime import unquote_slashes from lms.lib.xblock.runtime import unquote_slashes
......
...@@ -16,8 +16,6 @@ os.environ['SERVICE_VARIANT'] = 'bok_choy' ...@@ -16,8 +16,6 @@ os.environ['SERVICE_VARIANT'] = 'bok_choy'
os.environ['CONFIG_ROOT'] = path(__file__).abspath().dirname() #pylint: disable=E1120 os.environ['CONFIG_ROOT'] = path(__file__).abspath().dirname() #pylint: disable=E1120
from .aws import * # pylint: disable=W0401, W0614 from .aws import * # pylint: disable=W0401, W0614
from xmodule.x_module import prefer_xmodules
######################### Testing overrides #################################### ######################### Testing overrides ####################################
...@@ -49,8 +47,5 @@ for log_name, log_level in LOG_OVERRIDES: ...@@ -49,8 +47,5 @@ for log_name, log_level in LOG_OVERRIDES:
# Use the auto_auth workflow for creating users and logging them in # Use the auto_auth workflow for creating users and logging them in
FEATURES['AUTOMATIC_AUTH_FOR_TESTING'] = True FEATURES['AUTOMATIC_AUTH_FOR_TESTING'] = True
# Enable XBlocks
XBLOCK_SELECT_FUNCTION = prefer_xmodules
# Unfortunately, we need to use debug mode to serve staticfiles # Unfortunately, we need to use debug mode to serve staticfiles
DEBUG = True DEBUG = True
...@@ -24,6 +24,7 @@ Longer TODO: ...@@ -24,6 +24,7 @@ Longer TODO:
# want to import all variables from base settings files # want to import all variables from base settings files
# pylint: disable=W0401, W0611, W0614 # pylint: disable=W0401, W0611, W0614
import imp
import sys import sys
import lms.envs.common import lms.envs.common
from lms.envs.common import ( from lms.envs.common import (
...@@ -33,8 +34,6 @@ from path import path ...@@ -33,8 +34,6 @@ from path import path
from lms.lib.xblock.mixin import LmsBlockMixin from lms.lib.xblock.mixin import LmsBlockMixin
from cms.lib.xblock.mixin import CmsBlockMixin from cms.lib.xblock.mixin import CmsBlockMixin
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.x_module import XModuleMixin, prefer_xmodules
from dealer.git import git from dealer.git import git
############################ FEATURE CONFIGURATION ############################# ############################ FEATURE CONFIGURATION #############################
...@@ -218,6 +217,10 @@ X_FRAME_OPTIONS = 'ALLOW' ...@@ -218,6 +217,10 @@ X_FRAME_OPTIONS = 'ALLOW'
############# XBlock Configuration ########## ############# XBlock Configuration ##########
# Import after sys.path fixup
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.x_module import XModuleMixin, prefer_xmodules
# This should be moved into an XBlock Runtime/Application object # This should be moved into an XBlock Runtime/Application object
# once the responsibility of XBlock creation is moved out of modulestore - cpennington # once the responsibility of XBlock creation is moved out of modulestore - cpennington
XBLOCK_MIXINS = (LmsBlockMixin, CmsBlockMixin, InheritanceMixin, XModuleMixin) XBLOCK_MIXINS = (LmsBlockMixin, CmsBlockMixin, InheritanceMixin, XModuleMixin)
...@@ -467,9 +470,6 @@ INSTALLED_APPS = ( ...@@ -467,9 +470,6 @@ INSTALLED_APPS = (
# for course creator table # for course creator table
'django.contrib.admin', 'django.contrib.admin',
# XBlocks containing migrations
'mentoring',
# for managing course modes # for managing course modes
'course_modes', 'course_modes',
...@@ -536,11 +536,22 @@ MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED = 5 ...@@ -536,11 +536,22 @@ MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED = 5
MAX_FAILED_LOGIN_ATTEMPTS_LOCKOUT_PERIOD_SECS = 15 * 60 MAX_FAILED_LOGIN_ATTEMPTS_LOCKOUT_PERIOD_SECS = 15 * 60
### JSdraw (only installed in some instances) ### Apps only installed in some instances
OPTIONAL_APPS = (
'edx_jsdraw',
'mentoring',
)
try: for app_name in OPTIONAL_APPS:
import edx_jsdraw # First attempt to only find the module rather than actually importing it,
except ImportError: # to avoid circular references - only try to import if it can't be found
pass # by find_module, which doesn't work with import hooks
else: try:
INSTALLED_APPS += ('edx_jsdraw',) imp.find_module(app_name)
except ImportError:
try:
__import__(app_name)
except ImportError:
continue
INSTALLED_APPS += (app_name,)
...@@ -157,11 +157,6 @@ INSTALLED_APPS += ('external_auth', ) ...@@ -157,11 +157,6 @@ INSTALLED_APPS += ('external_auth', )
filterwarnings('ignore', message='No request passed to the backend, unable to rate-limit') filterwarnings('ignore', message='No request passed to the backend, unable to rate-limit')
################################# XBLOCK ######################################
from xmodule.x_module import prefer_xmodules
XBLOCK_SELECT_FUNCTION = prefer_xmodules
################################# CELERY ###################################### ################################# CELERY ######################################
CELERY_ALWAYS_EAGER = True CELERY_ALWAYS_EAGER = True
......
...@@ -229,7 +229,7 @@ class AboutFields(object): ...@@ -229,7 +229,7 @@ class AboutFields(object):
) )
data = String( data = String(
help="Html contents to display for this module", help="Html contents to display for this module",
default="", default=u"",
scope=Scope.content scope=Scope.content
) )
...@@ -263,7 +263,7 @@ class StaticTabFields(object): ...@@ -263,7 +263,7 @@ class StaticTabFields(object):
default="Empty", default="Empty",
) )
data = String( data = String(
default=textwrap.dedent("""\ default=textwrap.dedent(u"""\
<p>This is where you can add additional pages to your courseware. Click the 'edit' button to begin editing.</p> <p>This is where you can add additional pages to your courseware. Click the 'edit' button to begin editing.</p>
"""), """),
scope=Scope.content, scope=Scope.content,
...@@ -300,7 +300,7 @@ class CourseInfoFields(object): ...@@ -300,7 +300,7 @@ class CourseInfoFields(object):
) )
data = String( data = String(
help="Html contents to display for this module", help="Html contents to display for this module",
default="<ol></ol>", default=u"<ol></ol>",
scope=Scope.content scope=Scope.content
) )
......
...@@ -60,6 +60,9 @@ class MongoKeyValueStore(InheritanceKeyValueStore): ...@@ -60,6 +60,9 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
""" """
def __init__(self, data, children, metadata): def __init__(self, data, children, metadata):
super(MongoKeyValueStore, self).__init__() super(MongoKeyValueStore, self).__init__()
if not isinstance(data, dict):
self._data = {'data': data}
else:
self._data = data self._data = data
self._children = children self._children = children
self._metadata = metadata self._metadata = metadata
...@@ -72,9 +75,6 @@ class MongoKeyValueStore(InheritanceKeyValueStore): ...@@ -72,9 +75,6 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
elif key.scope == Scope.settings: elif key.scope == Scope.settings:
return self._metadata[key.field_name] return self._metadata[key.field_name]
elif key.scope == Scope.content: elif key.scope == Scope.content:
if key.field_name == 'data' and not isinstance(self._data, dict):
return self._data
else:
return self._data[key.field_name] return self._data[key.field_name]
else: else:
raise InvalidScopeError(key) raise InvalidScopeError(key)
...@@ -85,9 +85,6 @@ class MongoKeyValueStore(InheritanceKeyValueStore): ...@@ -85,9 +85,6 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
elif key.scope == Scope.settings: elif key.scope == Scope.settings:
self._metadata[key.field_name] = value self._metadata[key.field_name] = value
elif key.scope == Scope.content: elif key.scope == Scope.content:
if key.field_name == 'data' and not isinstance(self._data, dict):
self._data = value
else:
self._data[key.field_name] = value self._data[key.field_name] = value
else: else:
raise InvalidScopeError(key) raise InvalidScopeError(key)
...@@ -99,9 +96,7 @@ class MongoKeyValueStore(InheritanceKeyValueStore): ...@@ -99,9 +96,7 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
if key.field_name in self._metadata: if key.field_name in self._metadata:
del self._metadata[key.field_name] del self._metadata[key.field_name]
elif key.scope == Scope.content: elif key.scope == Scope.content:
if key.field_name == 'data' and not isinstance(self._data, dict): if key.field_name in self._data:
self._data = None
else:
del self._data[key.field_name] del self._data[key.field_name]
else: else:
raise InvalidScopeError(key) raise InvalidScopeError(key)
...@@ -112,9 +107,6 @@ class MongoKeyValueStore(InheritanceKeyValueStore): ...@@ -112,9 +107,6 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
elif key.scope == Scope.settings: elif key.scope == Scope.settings:
return key.field_name in self._metadata return key.field_name in self._metadata
elif key.scope == Scope.content: elif key.scope == Scope.content:
if key.field_name == 'data' and not isinstance(self._data, dict):
return True
else:
return key.field_name in self._data return key.field_name in self._data
else: else:
return False return False
...@@ -640,6 +632,10 @@ class MongoModuleStore(ModuleStoreWriteBase): ...@@ -640,6 +632,10 @@ class MongoModuleStore(ModuleStoreWriteBase):
# layer but added it here to enable quick conversion. I'll need to reconcile these. # layer but added it here to enable quick conversion. I'll need to reconcile these.
if metadata is None: if metadata is None:
metadata = {} metadata = {}
if definition_data is None:
definition_data = {}
if system is None: if system is None:
services = {} services = {}
if self.i18n_service: if self.i18n_service:
...@@ -658,11 +654,6 @@ class MongoModuleStore(ModuleStoreWriteBase): ...@@ -658,11 +654,6 @@ class MongoModuleStore(ModuleStoreWriteBase):
services=services, services=services,
) )
xblock_class = system.load_block_type(location.category) xblock_class = system.load_block_type(location.category)
if definition_data is None:
if hasattr(xblock_class, 'data') and xblock_class.data.default is not None:
definition_data = xblock_class.data.default
else:
definition_data = {}
dbmodel = self._create_new_field_data(location.category, location, definition_data, metadata) dbmodel = self._create_new_field_data(location.category, location, definition_data, metadata)
xmodule = system.construct_xblock_from_class( xmodule = system.construct_xblock_from_class(
xblock_class, xblock_class,
...@@ -796,8 +787,6 @@ class MongoModuleStore(ModuleStoreWriteBase): ...@@ -796,8 +787,6 @@ class MongoModuleStore(ModuleStoreWriteBase):
""" """
try: try:
definition_data = xblock.get_explicitly_set_fields_by_scope() definition_data = xblock.get_explicitly_set_fields_by_scope()
if len(definition_data) == 1 and 'data' in definition_data:
definition_data = definition_data['data']
payload = { payload = {
'definition.data': definition_data, 'definition.data': definition_data,
'metadata': own_metadata(xblock), 'metadata': own_metadata(xblock),
......
...@@ -56,7 +56,6 @@ import copy ...@@ -56,7 +56,6 @@ import copy
from pytz import UTC from pytz import UTC
from xmodule.errortracker import null_error_tracker from xmodule.errortracker import null_error_tracker
from xmodule.x_module import prefer_xmodules
from xmodule.modulestore.locator import ( from xmodule.modulestore.locator import (
BlockUsageLocator, DefinitionLocator, CourseLocator, VersionTree, LocalId, Locator BlockUsageLocator, DefinitionLocator, CourseLocator, VersionTree, LocalId, Locator
) )
......
...@@ -299,7 +299,7 @@ class TestMongoKeyValueStore(object): ...@@ -299,7 +299,7 @@ class TestMongoKeyValueStore(object):
assert_false(self.kvs.has(key)) assert_false(self.kvs.has(key))
def test_read_non_dict_data(self): def test_read_non_dict_data(self):
self.kvs._data = 'xml_data' self.kvs = MongoKeyValueStore('xml_data', self.children, self.metadata)
assert_equals('xml_data', self.kvs.get(KeyValueStore.Key(Scope.content, None, None, 'data'))) assert_equals('xml_data', self.kvs.get(KeyValueStore.Key(Scope.content, None, None, 'data')))
def _check_write(self, key, value): def _check_write(self, key, value):
...@@ -312,7 +312,7 @@ class TestMongoKeyValueStore(object): ...@@ -312,7 +312,7 @@ class TestMongoKeyValueStore(object):
yield (self._check_write, KeyValueStore.Key(Scope.settings, None, None, 'meta'), 'new_settings') yield (self._check_write, KeyValueStore.Key(Scope.settings, None, None, 'meta'), 'new_settings')
def test_write_non_dict_data(self): def test_write_non_dict_data(self):
self.kvs._data = 'xml_data' self.kvs = MongoKeyValueStore('xml_data', self.children, self.metadata)
self._check_write(KeyValueStore.Key(Scope.content, None, None, 'data'), 'new_data') self._check_write(KeyValueStore.Key(Scope.content, None, None, 'data'), 'new_data')
def test_write_invalid_scope(self): def test_write_invalid_scope(self):
......
...@@ -4,8 +4,6 @@ Settings for bok choy tests ...@@ -4,8 +4,6 @@ Settings for bok choy tests
import os import os
from path import path from path import path
from xmodule.x_module import prefer_xmodules
CONFIG_ROOT = path(__file__).abspath().dirname() #pylint: disable=E1120 CONFIG_ROOT = path(__file__).abspath().dirname() #pylint: disable=E1120
TEST_ROOT = CONFIG_ROOT.dirname().dirname() / "test_root" TEST_ROOT = CONFIG_ROOT.dirname().dirname() / "test_root"
...@@ -60,8 +58,5 @@ LOG_OVERRIDES = [ ...@@ -60,8 +58,5 @@ LOG_OVERRIDES = [
for log_name, log_level in LOG_OVERRIDES: for log_name, log_level in LOG_OVERRIDES:
logging.getLogger(log_name).setLevel(log_level) logging.getLogger(log_name).setLevel(log_level)
# Enable XBlocks
XBLOCK_SELECT_FUNCTION = prefer_xmodules
# Unfortunately, we need to use debug mode to serve staticfiles # Unfortunately, we need to use debug mode to serve staticfiles
DEBUG = True DEBUG = True
...@@ -26,6 +26,7 @@ Longer TODO: ...@@ -26,6 +26,7 @@ Longer TODO:
import sys import sys
import os import os
import imp
import json import json
from path import path from path import path
...@@ -33,8 +34,6 @@ from path import path ...@@ -33,8 +34,6 @@ from path import path
from .discussionsettings import * from .discussionsettings import *
from lms.lib.xblock.mixin import LmsBlockMixin from lms.lib.xblock.mixin import LmsBlockMixin
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.x_module import XModuleMixin, prefer_xmodules
################################### FEATURES ################################### ################################### FEATURES ###################################
# The display name of the platform to be used in templates/emails/etc. # The display name of the platform to be used in templates/emails/etc.
...@@ -431,6 +430,10 @@ DOC_STORE_CONFIG = { ...@@ -431,6 +430,10 @@ DOC_STORE_CONFIG = {
############# XBlock Configuration ########## ############# XBlock Configuration ##########
# Import after sys.path fixup
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.x_module import XModuleMixin, prefer_xmodules
# This should be moved into an XBlock Runtime/Application object # This should be moved into an XBlock Runtime/Application object
# once the responsibility of XBlock creation is moved out of modulestore - cpennington # once the responsibility of XBlock creation is moved out of modulestore - cpennington
XBLOCK_MIXINS = (LmsBlockMixin, InheritanceMixin, XModuleMixin) XBLOCK_MIXINS = (LmsBlockMixin, InheritanceMixin, XModuleMixin)
...@@ -1163,9 +1166,6 @@ INSTALLED_APPS = ( ...@@ -1163,9 +1166,6 @@ INSTALLED_APPS = (
'reverification', 'reverification',
'embargo', 'embargo',
# XBlocks containing migrations
'mentoring',
) )
######################### MARKETING SITE ############################### ######################### MARKETING SITE ###############################
...@@ -1458,11 +1458,22 @@ ALL_LANGUAGES = ( ...@@ -1458,11 +1458,22 @@ ALL_LANGUAGES = (
) )
### JSdraw (only installed in some instances) ### Apps only installed in some instances
try: OPTIONAL_APPS = (
import edx_jsdraw 'edx_jsdraw',
except ImportError: 'mentoring',
pass )
else:
INSTALLED_APPS += ('edx_jsdraw',) for app_name in OPTIONAL_APPS:
# First attempt to only find the module rather than actually importing it,
# to avoid circular references - only try to import if it can't be found
# by find_module, which doesn't work with import hooks
try:
imp.find_module(app_name)
except ImportError:
try:
__import__(app_name)
except ImportError:
continue
INSTALLED_APPS += (app_name,)
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