Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
-c constraints.txt

django-statici18n
edx-django-utils
edx-i18n-tools
edx-opaque-keys
edxval
nh3
oauthlib
openedx-django-pyfs
wrapt
XBlock
35 changes: 35 additions & 0 deletions xblocks_contrib/common/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Common utility functions for XBlocks.
"""

from django.conf import settings



def get_resource_url(xblock, path, package_scope=None):
"""
Return the runtime URL for a static resource in this XBlock's package.

When the Django pipeline is enabled or REQUIRE_DEBUG is False, uses the
pipeline path (e.g. {package_scope}/public/{path}). Otherwise uses the
dev path (e.g. public/{path}). See platform's xblock_local_resource_url() in:
openedx/core/lib/xblock_utils/__init__.py

Arguments:
xblock: The XBlock instance (for runtime.local_resource_url).
path (str): Relative path within the package, e.g. "css/video.css".
package_scope (str): Package name prefix, e.g. "video". If None,
both paths are "public/{path}"; otherwise pipeline adds the prefix.

Returns:
str: URL from xblock.runtime.local_resource_url() for the resource.
"""
pipeline_path = dev_path = f"public/{path}"
if package_scope:
pipeline_path = f"{package_scope}/{pipeline_path}"
pipeline = getattr(settings, 'PIPELINE', {})
if pipeline.get('PIPELINE_ENABLED', True) or not getattr(settings, 'REQUIRE_DEBUG', False):
resource_path = pipeline_path
else:
resource_path = dev_path
return xblock.runtime.local_resource_url(xblock, resource_path)
17 changes: 10 additions & 7 deletions xblocks_contrib/video/ajax_handler_mixin.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# NOTE: Code has been copied from the following source file
# https://github.com/openedx/edx-platform/blob/master/xmodule/x_module.py#L739
""" Mixin that provides AJAX handling for Video XBlock """
from webob import Response
from webob.multidict import MultiDict
from xblock.core import XBlock

class XModuleToXBlockMixin:

class AjaxHandlerMixin:
"""
Common code needed by XModule and XBlocks converted from XModules.
Mixin that provides AJAX handling for Video XBlock
"""
@property
def ajax_url(self):
"""
Returns the URL for the ajax handler.
"""
return self.runtime.handler_url(self, 'xmodule_handler', '', '').rstrip('/?')
return self.runtime.handler_url(self, 'ajax_handler', '', '').rstrip('/?')

@XBlock.handler
def xmodule_handler(self, request, suffix=None):
def ajax_handler(self, request, suffix=None):
"""
XBlock handler that wraps `handle_ajax`
XBlock handler that wraps `ajax_handler`
"""
class FileObjForWebobFiles:
"""
Expand Down
Loading
Loading