Merge pull request #31173 from open-craft/maxim/remove-unused-xmodule-classes
[BD-13] refactor: Remove unused XModule classes
This commit is contained in:
@@ -16,27 +16,6 @@ Note: Hotfix (PLAT-734) No asset calls find_asset_metadata, and directly accesse
|
||||
from xmodule.contentstore.django import contentstore
|
||||
|
||||
|
||||
class AssetException(Exception):
|
||||
"""
|
||||
Base exception class for all exceptions related to assets.
|
||||
"""
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
|
||||
class AssetMetadataNotFound(AssetException):
|
||||
"""
|
||||
Thrown when no asset metadata is present in the course modulestore for the particular asset requested.
|
||||
"""
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
|
||||
class AssetMetadataFoundTemporary(AssetException):
|
||||
"""
|
||||
TEMPORARY: Thrown if asset metadata is actually found in the course modulestore.
|
||||
"""
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
|
||||
class AssetManager:
|
||||
"""
|
||||
Manager for saving/loading course assets.
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
|
||||
import logging
|
||||
|
||||
from pkg_resources import resource_string
|
||||
from xblock.fields import Scope, String
|
||||
|
||||
from xmodule.mako_module import MakoModuleDescriptor, MakoTemplateBlockBase
|
||||
from xmodule.mako_module import MakoTemplateBlockBase
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -44,91 +43,3 @@ class EditingMixin(EditingFields, MakoTemplateBlockBase):
|
||||
# Add our specific template information (the raw data body)
|
||||
_context.update({'data': self.data})
|
||||
return _context
|
||||
|
||||
|
||||
class EditingDescriptor(EditingMixin, MakoModuleDescriptor): # lint-amnesty, pylint: disable=abstract-method
|
||||
pass
|
||||
|
||||
|
||||
class TabsEditingMixin(EditingFields, MakoTemplateBlockBase):
|
||||
"""
|
||||
Common code between TabsEditingDescriptor and XBlocks converted from XModules.
|
||||
"""
|
||||
|
||||
mako_template = "widgets/tabs-aggregator.html"
|
||||
css = {'scss': [resource_string(__name__, 'css/tabs/tabs.scss')]}
|
||||
js = {'js': [resource_string(
|
||||
__name__, 'js/src/tabs/tabs-aggregator.js')]}
|
||||
js_module_name = "TabsEditingDescriptor"
|
||||
tabs = []
|
||||
|
||||
def get_context(self):
|
||||
_context = MakoTemplateBlockBase.get_context(self)
|
||||
_context.update({
|
||||
'tabs': self.tabs,
|
||||
'html_id': self.location.html_id(), # element_id
|
||||
'data': self.data,
|
||||
})
|
||||
return _context
|
||||
|
||||
@classmethod
|
||||
def get_css(cls): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
# load every tab's css
|
||||
for tab in cls.tabs:
|
||||
tab_styles = tab.get('css', {})
|
||||
for css_type, css_content in tab_styles.items():
|
||||
if css_type in cls.css:
|
||||
cls.css[css_type].extend(css_content)
|
||||
else:
|
||||
cls.css[css_type] = css_content
|
||||
return cls.css
|
||||
|
||||
|
||||
class TabsEditingDescriptor(TabsEditingMixin, MakoModuleDescriptor): # lint-amnesty, pylint: disable=abstract-method
|
||||
"""
|
||||
Module that provides a raw editing view of its data and children. It does not
|
||||
perform any validation on its definition---just passes it along to the browser.
|
||||
|
||||
This class is intended to be used as a mixin.
|
||||
|
||||
Engine (module_edit.js) wants for metadata editor
|
||||
template to be always loaded, so don't forget to include
|
||||
settings tab in your module descriptor.
|
||||
"""
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
|
||||
class XMLEditingDescriptor(EditingDescriptor): # lint-amnesty, pylint: disable=abstract-method
|
||||
"""
|
||||
Module that provides a raw editing view of its data as XML. It does not perform
|
||||
any validation of its definition
|
||||
"""
|
||||
|
||||
css = {'scss': [resource_string(__name__, 'css/codemirror/codemirror.scss')]}
|
||||
|
||||
js = {'js': [resource_string(__name__, 'js/src/raw/edit/xml.js')]}
|
||||
js_module_name = "XMLEditingDescriptor"
|
||||
|
||||
|
||||
class MetadataOnlyEditingDescriptor(EditingDescriptor): # lint-amnesty, pylint: disable=abstract-method
|
||||
"""
|
||||
Module which only provides an editing interface for the metadata, it does
|
||||
not expose a UI for editing the module data
|
||||
"""
|
||||
|
||||
js = {'js': [resource_string(__name__, 'js/src/raw/edit/metadata-only.js')]}
|
||||
js_module_name = "MetadataOnlyEditingDescriptor"
|
||||
|
||||
mako_template = "widgets/metadata-only-edit.html"
|
||||
|
||||
|
||||
class JSONEditingDescriptor(EditingDescriptor): # lint-amnesty, pylint: disable=abstract-method
|
||||
"""
|
||||
Module that provides a raw editing view of its data as XML. It does not perform
|
||||
any validation of its definition
|
||||
"""
|
||||
|
||||
css = {'scss': [resource_string(__name__, 'css/codemirror/codemirror.scss')]}
|
||||
|
||||
js = {'js': [resource_string(__name__, 'js/src/raw/edit/json.js')]}
|
||||
js_module_name = "JSONEditingDescriptor"
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
// Once generated by CoffeeScript 1.9.3, but now lives as pure JS
|
||||
/* eslint-disable */
|
||||
(function() {
|
||||
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
this.JSONEditingDescriptor = (function(superClass) {
|
||||
extend(JSONEditingDescriptor, superClass);
|
||||
|
||||
function JSONEditingDescriptor(element) {
|
||||
this.element = element;
|
||||
this.edit_box = CodeMirror.fromTextArea($(".edit-box", this.element)[0], {
|
||||
mode: {
|
||||
name: "javascript",
|
||||
json: true
|
||||
},
|
||||
lineNumbers: true,
|
||||
lineWrapping: true
|
||||
});
|
||||
}
|
||||
|
||||
JSONEditingDescriptor.prototype.save = function() {
|
||||
return {
|
||||
data: JSON.parse(this.edit_box.getValue())
|
||||
};
|
||||
};
|
||||
|
||||
return JSONEditingDescriptor;
|
||||
|
||||
})(XModule.Descriptor);
|
||||
|
||||
}).call(this);
|
||||
@@ -8,7 +8,7 @@ import logging
|
||||
from web_fragments.fragment import Fragment
|
||||
from xblock.core import XBlock
|
||||
from xblock.fields import Boolean, List, Scope, String
|
||||
from xmodule.studio_editable import StudioEditableModule
|
||||
from xmodule.studio_editable import StudioEditableBlock
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -87,7 +87,7 @@ class LibraryRoot(XBlock):
|
||||
child_context['show_preview'] = self.show_children_previews
|
||||
child_context['can_edit_visibility'] = False
|
||||
child = self.runtime.get_block(child_key)
|
||||
child_view_name = StudioEditableModule.get_preview_view_name(child)
|
||||
child_view_name = StudioEditableBlock.get_preview_view_name(child)
|
||||
|
||||
if str(child.location) == force_render:
|
||||
child_context['show_preview'] = True
|
||||
|
||||
@@ -4,9 +4,8 @@ Code to handle mako templating for XModules and XBlocks.
|
||||
|
||||
|
||||
from web_fragments.fragment import Fragment
|
||||
from xblock.core import XBlock
|
||||
|
||||
from .x_module import DescriptorSystem, shim_xmodule_js, XModuleMixin
|
||||
from .x_module import DescriptorSystem, shim_xmodule_js
|
||||
|
||||
|
||||
class MakoDescriptorSystem(DescriptorSystem): # lint-amnesty, pylint: disable=abstract-method
|
||||
@@ -72,14 +71,3 @@ class MakoTemplateBlockBase:
|
||||
)
|
||||
shim_xmodule_js(fragment, self.js_module_name)
|
||||
return fragment
|
||||
|
||||
|
||||
@XBlock.needs("i18n")
|
||||
class MakoModuleDescriptor(MakoTemplateBlockBase, XModuleMixin): # pylint: disable=abstract-method
|
||||
"""
|
||||
Mixin to use for XModule descriptors.
|
||||
"""
|
||||
resources_dir = None
|
||||
|
||||
def get_html(self):
|
||||
return self.studio_view(None).content
|
||||
|
||||
@@ -4,7 +4,6 @@ import re
|
||||
|
||||
from lxml import etree
|
||||
from xblock.fields import Scope, String
|
||||
from xmodule.editing_module import XMLEditingDescriptor # pylint: disable=unused-import
|
||||
from xmodule.xml_module import XmlDescriptor # pylint: disable=unused-import
|
||||
|
||||
from .exceptions import SerializationError
|
||||
|
||||
@@ -25,7 +25,7 @@ class StudioEditableBlock(XBlockMixin):
|
||||
if can_reorder:
|
||||
context['reorderable_items'].add(child.location)
|
||||
context['can_add'] = can_add
|
||||
rendered_child = child.render(StudioEditableModule.get_preview_view_name(child), context)
|
||||
rendered_child = child.render(StudioEditableBlock.get_preview_view_name(child), context)
|
||||
fragment.add_fragment_resources(rendered_child)
|
||||
|
||||
contents.append({
|
||||
@@ -48,9 +48,6 @@ class StudioEditableBlock(XBlockMixin):
|
||||
return AUTHOR_VIEW if has_author_view(block) else STUDENT_VIEW
|
||||
|
||||
|
||||
StudioEditableModule = StudioEditableBlock
|
||||
|
||||
|
||||
def has_author_view(descriptor):
|
||||
"""
|
||||
Returns True if the xmodule linked to the descriptor supports "author_view".
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
""" Tests for editing descriptors"""
|
||||
|
||||
|
||||
import logging
|
||||
import os
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
|
||||
from pkg_resources import resource_string
|
||||
from xblock.field_data import DictFieldData
|
||||
from xblock.fields import ScopeIds
|
||||
|
||||
from xmodule.editing_module import TabsEditingDescriptor
|
||||
from xmodule.tests import get_test_descriptor_system
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TabsEditingDescriptorTestCase(unittest.TestCase):
|
||||
""" Testing TabsEditingDescriptor"""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
system = get_test_descriptor_system(render_template=Mock())
|
||||
self.tabs = [
|
||||
{
|
||||
'name': "Test_css",
|
||||
'template': "tabs/codemirror-edit.html",
|
||||
'current': True,
|
||||
'css': {
|
||||
'scss': [
|
||||
resource_string(
|
||||
__name__,
|
||||
'test_files/test_tabseditingdescriptor.scss'
|
||||
)
|
||||
],
|
||||
'css': [
|
||||
resource_string(
|
||||
__name__,
|
||||
'test_files/test_tabseditingdescriptor.css'
|
||||
)
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': "Subtitles",
|
||||
'template': "video/subtitles.html",
|
||||
},
|
||||
{
|
||||
'name': "Settings",
|
||||
'template': "tabs/video-metadata-edit-tab.html"
|
||||
}
|
||||
]
|
||||
|
||||
TabsEditingDescriptor.tabs = self.tabs
|
||||
self.descriptor = system.construct_xblock_from_class(
|
||||
TabsEditingDescriptor,
|
||||
scope_ids=ScopeIds(None, None, None,
|
||||
BlockUsageLocator(CourseLocator('org', 'course', 'run', branch='revision'),
|
||||
'category', 'name')),
|
||||
field_data=DictFieldData({}),
|
||||
)
|
||||
|
||||
def test_get_css(self):
|
||||
"""test get_css"""
|
||||
css = self.descriptor.get_css()
|
||||
current_dir = os.path.dirname(__file__)
|
||||
test_css_file = os.path.join(current_dir, 'test_files/test_tabseditingdescriptor.scss')
|
||||
with open(test_css_file) as new_css:
|
||||
added_css = new_css.read()
|
||||
assert css['scss'].pop().decode('utf-8') == added_css
|
||||
assert css['css'].pop().decode('utf-8') == added_css
|
||||
|
||||
def test_get_context(self):
|
||||
""""test get_context"""
|
||||
rendered_context = self.descriptor.get_context()
|
||||
self.assertListEqual(rendered_context['tabs'], self.tabs)
|
||||
@@ -7,7 +7,6 @@ import pytest
|
||||
from pytz import UTC
|
||||
|
||||
from xmodule.fields import Date, RelativeTime, Timedelta
|
||||
from xmodule.timeinfo import TimeInfo
|
||||
|
||||
|
||||
class DateTest(unittest.TestCase): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
@@ -117,15 +116,6 @@ class TimedeltaTest(unittest.TestCase): # lint-amnesty, pylint: disable=missing
|
||||
TimedeltaTest.delta.to_json(datetime.timedelta(days=1, hours=12, minutes=59, seconds=59))
|
||||
|
||||
|
||||
class TimeInfoTest(unittest.TestCase): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
|
||||
def test_time_info(self):
|
||||
due_date = datetime.datetime(2000, 4, 14, 10, tzinfo=UTC)
|
||||
grace_pd_string = '1 day 12 hours 59 minutes 59 seconds'
|
||||
timeinfo = TimeInfo(due_date, grace_pd_string)
|
||||
assert timeinfo.close_date == (due_date + Timedelta().from_json(grace_pd_string))
|
||||
|
||||
|
||||
class RelativeTimeTest(unittest.TestCase): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
|
||||
delta = RelativeTime()
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
.supertestclass {
|
||||
color: red;
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
.supertestclass {
|
||||
color: red;
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
""" Test mako_module.py """
|
||||
|
||||
|
||||
from unittest import TestCase
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from xmodule.mako_module import MakoModuleDescriptor
|
||||
|
||||
|
||||
class MakoModuleTest(TestCase):
|
||||
""" Test MakoModuleDescriptor """
|
||||
|
||||
def test_render_template_check(self):
|
||||
mock_system = Mock()
|
||||
mock_system.render_template = None
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
MakoModuleDescriptor(mock_system, {})
|
||||
|
||||
del mock_system.render_template
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
MakoModuleDescriptor(mock_system, {})
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Tests for StudioEditableModule.
|
||||
Tests for StudioEditableBlock.
|
||||
"""
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ from xmodule.tests.test_vertical import BaseVerticalBlockTest
|
||||
from xmodule.x_module import AUTHOR_VIEW
|
||||
|
||||
|
||||
class StudioEditableModuleTestCase(BaseVerticalBlockTest):
|
||||
class StudioEditableBlockTestCase(BaseVerticalBlockTest):
|
||||
"""
|
||||
Class containing StudioEditableModule tests.
|
||||
Class containing StudioEditableBlock tests.
|
||||
"""
|
||||
|
||||
def test_render_reorderable_children(self):
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
# lint-amnesty, pylint: disable=missing-module-docstring
|
||||
|
||||
import logging
|
||||
|
||||
from xmodule.fields import Timedelta
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TimeInfo:
|
||||
"""
|
||||
This is a simple object that calculates and stores datetime information for an XModule
|
||||
based on the due date and the grace period string
|
||||
|
||||
So far it parses out three different pieces of time information:
|
||||
self.display_due_date - the 'official' due date that gets displayed to students
|
||||
self.grace_period - the length of the grace period
|
||||
self.close_date - the real due date
|
||||
|
||||
"""
|
||||
_delta_standin = Timedelta()
|
||||
|
||||
def __init__(self, due_date, grace_period_string_or_timedelta):
|
||||
if due_date is not None:
|
||||
self.display_due_date = due_date
|
||||
|
||||
else:
|
||||
self.display_due_date = None
|
||||
|
||||
if grace_period_string_or_timedelta is not None and self.display_due_date:
|
||||
if isinstance(grace_period_string_or_timedelta, str):
|
||||
try:
|
||||
self.grace_period = TimeInfo._delta_standin.from_json(grace_period_string_or_timedelta)
|
||||
except:
|
||||
log.error(f"Error parsing the grace period {grace_period_string_or_timedelta}")
|
||||
raise
|
||||
else:
|
||||
self.grace_period = grace_period_string_or_timedelta
|
||||
self.close_date = self.display_due_date + self.grace_period
|
||||
else:
|
||||
self.grace_period = None
|
||||
self.close_date = self.display_due_date
|
||||
@@ -35,8 +35,9 @@ from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTU
|
||||
from openedx.core.lib.cache_utils import request_cached
|
||||
from openedx.core.lib.license import LicenseMixin
|
||||
from xmodule.contentstore.content import StaticContent
|
||||
from xmodule.editing_module import EditingMixin, TabsEditingMixin
|
||||
from xmodule.editing_module import EditingMixin
|
||||
from xmodule.exceptions import NotFoundError
|
||||
from xmodule.mako_module import MakoTemplateBlockBase
|
||||
from xmodule.modulestore.inheritance import InheritanceKeyValueStore, own_metadata
|
||||
from xmodule.raw_module import EmptyDataRawMixin
|
||||
from xmodule.validation import StudioValidation, StudioValidationMessage
|
||||
@@ -112,9 +113,8 @@ EXPORT_IMPORT_STATIC_DIR = 'static'
|
||||
@XBlock.needs('mako', 'user')
|
||||
class VideoBlock(
|
||||
VideoFields, VideoTranscriptsMixin, VideoStudioViewHandlers, VideoStudentViewHandlers,
|
||||
TabsEditingMixin, EmptyDataRawMixin, XmlMixin, EditingMixin,
|
||||
XModuleToXBlockMixin, HTMLSnippet, ResourceTemplates, XModuleMixin,
|
||||
LicenseMixin):
|
||||
EmptyDataRawMixin, XmlMixin, EditingMixin, XModuleToXBlockMixin, HTMLSnippet,
|
||||
ResourceTemplates, XModuleMixin, LicenseMixin):
|
||||
"""
|
||||
XML source example:
|
||||
<video show_captions="true"
|
||||
@@ -146,6 +146,9 @@ class VideoBlock(
|
||||
}
|
||||
]
|
||||
|
||||
mako_template = "widgets/tabs-aggregator.html"
|
||||
js_module_name = "TabsEditingDescriptor"
|
||||
|
||||
uses_xmodule_styles_setup = True
|
||||
requires_per_student_anonymous_id = True
|
||||
|
||||
@@ -793,7 +796,12 @@ class VideoBlock(
|
||||
"""
|
||||
Extend context by data for transcript basic tab.
|
||||
"""
|
||||
_context = super().get_context()
|
||||
_context = MakoTemplateBlockBase.get_context(self)
|
||||
_context.update({
|
||||
'tabs': self.tabs,
|
||||
'html_id': self.location.html_id(), # element_id
|
||||
'data': self.data,
|
||||
})
|
||||
|
||||
metadata_fields = copy.deepcopy(self.editable_metadata_fields)
|
||||
|
||||
|
||||
@@ -205,10 +205,6 @@ class AsideKeyGenerator(IdGenerator):
|
||||
raise NotImplementedError("Specific Modulestores must provide implementations of create_definition")
|
||||
|
||||
|
||||
def dummy_track(_event_type, _event):
|
||||
pass
|
||||
|
||||
|
||||
class HTMLSnippet:
|
||||
"""
|
||||
A base class defining an interface for an object that is able to present an
|
||||
|
||||
Reference in New Issue
Block a user