Skip to content

Commit 6c7a00a

Browse files
committed
feat: Update and fix the shifted Video XBlock code to make it run (#142)
1 parent 48cb3b9 commit 6c7a00a

21 files changed

+874
-469
lines changed

requirements/base.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
-c constraints.txt
33

44
django-statici18n
5+
edx-django-utils
56
edx-i18n-tools
67
edx-opaque-keys
8+
edxval
79
nh3
810
oauthlib
911
openedx-django-pyfs
12+
wrapt
1013
XBlock

xblocks_contrib/common/utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Common utility functions for XBlocks.
3+
"""
4+
5+
from django.conf import settings
6+
7+
8+
9+
def get_resource_url(xblock, path, package_scope=None):
10+
"""
11+
Return the runtime URL for a static resource in this XBlock's package.
12+
13+
When the Django pipeline is enabled or REQUIRE_DEBUG is False, uses the
14+
pipeline path (e.g. {package_scope}/public/{path}). Otherwise uses the
15+
dev path (e.g. public/{path}). See platform's xblock_local_resource_url() in:
16+
openedx/core/lib/xblock_utils/__init__.py
17+
18+
Arguments:
19+
xblock: The XBlock instance (for runtime.local_resource_url).
20+
path (str): Relative path within the package, e.g. "css/video.css".
21+
package_scope (str): Package name prefix, e.g. "video". If None,
22+
both paths are "public/{path}"; otherwise pipeline adds the prefix.
23+
24+
Returns:
25+
str: URL from xblock.runtime.local_resource_url() for the resource.
26+
"""
27+
pipeline_path = dev_path = f"public/{path}"
28+
if package_scope:
29+
pipeline_path = f"{package_scope}/{pipeline_path}"
30+
pipeline = getattr(settings, 'PIPELINE', {})
31+
if pipeline.get('PIPELINE_ENABLED', True) or not getattr(settings, 'REQUIRE_DEBUG', False):
32+
resource_path = pipeline_path
33+
else:
34+
resource_path = dev_path
35+
return xblock.runtime.local_resource_url(xblock, resource_path)

xblocks_contrib/video/ajax_handler_mixin.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
# NOTE: Code has been copied from the following source file
2-
# https://github.com/openedx/edx-platform/blob/master/xmodule/x_module.py#L739
1+
""" Mixin that provides AJAX handling for Video XBlock """
2+
from webob import Response
3+
from webob.multidict import MultiDict
4+
from xblock.core import XBlock
35

4-
class XModuleToXBlockMixin:
6+
7+
class AjaxHandlerMixin:
58
"""
6-
Common code needed by XModule and XBlocks converted from XModules.
9+
Mixin that provides AJAX handling for Video XBlock
710
"""
811
@property
912
def ajax_url(self):
1013
"""
1114
Returns the URL for the ajax handler.
1215
"""
13-
return self.runtime.handler_url(self, 'xmodule_handler', '', '').rstrip('/?')
16+
return self.runtime.handler_url(self, 'ajax_handler', '', '').rstrip('/?')
1417

1518
@XBlock.handler
16-
def xmodule_handler(self, request, suffix=None):
19+
def ajax_handler(self, request, suffix=None):
1720
"""
18-
XBlock handler that wraps `handle_ajax`
21+
XBlock handler that wraps `ajax_handler`
1922
"""
2023
class FileObjForWebobFiles:
2124
"""

0 commit comments

Comments
 (0)