Skip to content

Commit

Permalink
refactor: define resource paths (not contents) on XModule classes (#3…
Browse files Browse the repository at this point in the history
…2286)

For the XBlocks types that use legacy XModule-style assets (specifically, those that
inherit from `HTMLSnippet`), this is small refactor that brings them a bit closer to being like
standard XBlocks.

Given these class attributes:

    class SomeXModuleLikeBlock(..., HTMLSnippet, ...):
        ...
        studio_view_css = { ... }
        preview_view_css = { ... }
        studio_view_js = { ... }
        preview_view_js = { ... }
        ...

we make it so their values are *paths to the resources*
rather than *the actual content of the resources*.
This is a no-op change, but it'll enable future XModule
asset refactorings which require us to operate on asset
paths rather than contents.

Part of: #32292
  • Loading branch information
kdmccormick authored May 25, 2023
1 parent aa7370c commit 0f847df
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 89 deletions.
20 changes: 10 additions & 10 deletions xmodule/annotatable_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import textwrap

from lxml import etree
from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import Scope, String
Expand Down Expand Up @@ -75,28 +75,28 @@ class AnnotatableBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/html/display.js'),
resource_string(__name__, 'js/src/annotatable/display.js'),
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/collapsible.js'),
resource_filename(__name__, 'js/src/html/display.js'),
resource_filename(__name__, 'js/src/annotatable/display.js'),
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/collapsible.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [
resource_string(__name__, 'css/annotatable/display.scss'),
resource_filename(__name__, 'css/annotatable/display.scss'),
],
}

studio_view_js = {
'js': [
resource_string(__name__, 'js/src/raw/edit/xml.js'),
resource_filename(__name__, 'js/src/raw/edit/xml.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [
resource_string(__name__, 'css/codemirror/codemirror.scss'),
resource_filename(__name__, 'css/codemirror/codemirror.scss'),
],
}
studio_js_module_name = "XMLEditingDescriptor"
Expand Down
24 changes: 12 additions & 12 deletions xmodule/capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from django.utils.encoding import smart_str
from django.utils.functional import cached_property
from lxml import etree
from pkg_resources import resource_string
from pkg_resources import resource_filename
from pytz import utc
from web_fragments.fragment import Fragment
from xblock.core import XBlock
Expand Down Expand Up @@ -168,32 +168,32 @@ class ProblemBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/capa/display.js'),
resource_string(__name__, 'js/src/collapsible.js'),
resource_string(__name__, 'js/src/capa/imageinput.js'),
resource_string(__name__, 'js/src/capa/schematic.js'),
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/capa/display.js'),
resource_filename(__name__, 'js/src/collapsible.js'),
resource_filename(__name__, 'js/src/capa/imageinput.js'),
resource_filename(__name__, 'js/src/capa/schematic.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js')
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js')
}

preview_view_css = {
'scss': [
resource_string(__name__, 'css/capa/display.scss'),
resource_filename(__name__, 'css/capa/display.scss'),
],
}

studio_view_js = {
'js': [
resource_string(__name__, 'js/src/problem/edit.js'),
resource_filename(__name__, 'js/src/problem/edit.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}

studio_view_css = {
'scss': [
resource_string(__name__, 'css/editor/edit.scss'),
resource_string(__name__, 'css/problem/edit.scss'),
resource_filename(__name__, 'css/editor/edit.scss'),
resource_filename(__name__, 'css/problem/edit.scss'),
]
}

Expand Down
14 changes: 7 additions & 7 deletions xmodule/conditional_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from lazy import lazy
from lxml import etree
from opaque_keys.edx.locator import BlockUsageLocator
from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import ReferenceList, Scope, String
Expand Down Expand Up @@ -148,11 +148,11 @@ class ConditionalBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/conditional/display.js'),
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/collapsible.js'),
resource_filename(__name__, 'js/src/conditional/display.js'),
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/collapsible.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [],
Expand All @@ -161,8 +161,8 @@ class ConditionalBlock(
mako_template = 'widgets/metadata-edit.html'
studio_js_module_name = 'SequenceDescriptor'
studio_view_js = {
'js': [resource_string(__name__, 'js/src/sequence/edit.js')],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'js': [resource_filename(__name__, 'js/src/sequence/edit.js')],
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [],
Expand Down
24 changes: 12 additions & 12 deletions xmodule/html_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import textwrap
from datetime import datetime

from pkg_resources import resource_string
from pkg_resources import resource_filename

from django.conf import settings
from fs.errors import ResourceNotFound
Expand Down Expand Up @@ -144,15 +144,15 @@ def studio_view(self, _context):

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/html/display.js'),
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/collapsible.js'),
resource_string(__name__, 'js/src/html/imageModal.js'),
resource_string(__name__, 'js/common_static/js/vendor/draggabilly.js'),
resource_filename(__name__, 'js/src/html/display.js'),
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/collapsible.js'),
resource_filename(__name__, 'js/src/html/imageModal.js'),
resource_filename(__name__, 'js/common_static/js/vendor/draggabilly.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {'scss': [resource_string(__name__, 'css/html/display.scss')]}
preview_view_css = {'scss': [resource_filename(__name__, 'css/html/display.scss')]}

uses_xmodule_styles_setup = True

Expand All @@ -164,14 +164,14 @@ def studio_view(self, _context):

studio_view_js = {
'js': [
resource_string(__name__, 'js/src/html/edit.js')
resource_filename(__name__, 'js/src/html/edit.js')
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [
resource_string(__name__, 'css/editor/edit.scss'),
resource_string(__name__, 'css/html/edit.scss')
resource_filename(__name__, 'css/editor/edit.scss'),
resource_filename(__name__, 'css/html/edit.scss')
]
}

Expand Down
8 changes: 4 additions & 4 deletions xmodule/library_content_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from lxml import etree
from lxml.etree import XMLSyntaxError
from opaque_keys.edx.locator import LibraryLocator
from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment
from webob import Response
from xblock.completable import XBlockCompletionMode
Expand Down Expand Up @@ -97,7 +97,7 @@ class LibraryContentBlock(

preview_view_js = {
'js': [],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [],
Expand All @@ -107,9 +107,9 @@ class LibraryContentBlock(
studio_js_module_name = "VerticalDescriptor"
studio_view_js = {
'js': [
resource_string(__name__, 'js/src/vertical/edit.js'),
resource_filename(__name__, 'js/src/vertical/edit.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [],
Expand Down
12 changes: 6 additions & 6 deletions xmodule/lti_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from django.conf import settings
from lxml import etree
from oauthlib.oauth1.rfc5849 import signature
from pkg_resources import resource_string
from pkg_resources import resource_filename
from pytz import UTC
from webob import Response
from web_fragments.fragment import Fragment
Expand Down Expand Up @@ -374,13 +374,13 @@ class LTIBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/lti/lti.js')
resource_filename(__name__, 'js/src/lti/lti.js')
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [
resource_string(__name__, 'css/lti/lti.scss')
resource_filename(__name__, 'css/lti/lti.scss')
],
}

Expand All @@ -389,9 +389,9 @@ class LTIBlock(
studio_js_module_name = 'MetadataOnlyEditingDescriptor'
studio_view_js = {
'js': [
resource_string(__name__, 'js/src/raw/edit/metadata-only.js')
resource_filename(__name__, 'js/src/raw/edit/metadata-only.js')
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [],
Expand Down
14 changes: 7 additions & 7 deletions xmodule/poll_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from collections import OrderedDict
from copy import deepcopy

from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment

from lxml import etree
Expand Down Expand Up @@ -86,23 +86,23 @@ class PollBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/poll/poll.js'),
resource_string(__name__, 'js/src/poll/poll_main.js')
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/poll/poll.js'),
resource_filename(__name__, 'js/src/poll/poll_main.js')
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [
resource_string(__name__, 'css/poll/display.scss')
resource_filename(__name__, 'css/poll/display.scss')
],
}

# There is no studio_view() for this XBlock but this is needed to make the
# the static_content command happy.
studio_view_js = {
'js': [],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js')
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js')
}

studio_view_css = {
Expand Down
10 changes: 5 additions & 5 deletions xmodule/seq_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from lxml import etree
from opaque_keys.edx.keys import UsageKey
from pkg_resources import resource_string
from pkg_resources import resource_filename
from pytz import UTC
from web_fragments.fragment import Fragment
from xblock.completable import XBlockCompletionMode
Expand Down Expand Up @@ -273,22 +273,22 @@ class SequenceBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/sequence/display.js'),
resource_filename(__name__, 'js/src/sequence/display.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js')
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js')
}

preview_view_css = {
'scss': [
resource_string(__name__, 'css/sequence/display.scss'),
resource_filename(__name__, 'css/sequence/display.scss'),
],
}

# There is no studio_view() for this XBlock but this is needed to make the
# the static_content command happy.
studio_view_js = {
'js': [],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js')
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js')
}

studio_view_css = {
Expand Down
8 changes: 4 additions & 4 deletions xmodule/split_test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from django.utils.functional import cached_property
from lxml import etree
from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment
from webob import Response
from xblock.core import XBlock
Expand Down Expand Up @@ -160,7 +160,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method

preview_view_js = {
'js': [],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [],
Expand All @@ -169,8 +169,8 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
mako_template = "widgets/metadata-only-edit.html"
studio_js_module_name = 'SequenceDescriptor'
studio_view_js = {
'js': [resource_string(__name__, 'js/src/sequence/edit.js')],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'js': [resource_filename(__name__, 'js/src/sequence/edit.js')],
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [],
Expand Down
Loading

0 comments on commit 0f847df

Please sign in to comment.