Skip to content

Commit 7eae34b

Browse files
committed
chore: moved get_resource_url method to video_utils.py
1 parent bb01540 commit 7eae34b

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

xblocks_contrib/common/utils.py

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

xblocks_contrib/video/video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from xblock.fields import ScopeIds, UserScope
3535
from xblock.utils.resources import ResourceLoader
3636

37-
from xblocks_contrib.common.utils import get_resource_url
3837
from xblocks_contrib.common.xml_utils import (
3938
EdxJSONEncoder,
4039
LegacyXmlMixin,
@@ -63,6 +62,7 @@
6362
create_youtube_string,
6463
format_xml_exception_message,
6564
get_poster,
65+
get_resource_url,
6666
rewrite_video_url,
6767
)
6868
from xblocks_contrib.video.video_xfields import VideoFields

xblocks_contrib/video/video_utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,32 @@ def load_metadata_from_youtube(video_id, request):
183183
logging.warning('YouTube API key or video id is None. Please make sure API key and video id is not None')
184184

185185
return metadata, status_code
186+
187+
188+
def get_resource_url(xblock, path, package_scope=None):
189+
"""
190+
Return the runtime URL for a static resource in this XBlock's package.
191+
192+
When the Django pipeline is enabled or REQUIRE_DEBUG is False, uses the
193+
pipeline path (e.g. {package_scope}/public/{path}). Otherwise uses the
194+
dev path (e.g. public/{path}). See platform's xblock_local_resource_url() in:
195+
openedx/core/lib/xblock_utils/__init__.py
196+
197+
Arguments:
198+
xblock: The XBlock instance (for runtime.local_resource_url).
199+
path (str): Relative path within the package, e.g. "css/video.css".
200+
package_scope (str): Package name prefix, e.g. "video". If None,
201+
both paths are "public/{path}"; otherwise pipeline adds the prefix.
202+
203+
Returns:
204+
str: URL from xblock.runtime.local_resource_url() for the resource.
205+
"""
206+
pipeline_path = dev_path = f"public/{path}"
207+
if package_scope:
208+
pipeline_path = f"{package_scope}/{pipeline_path}"
209+
pipeline = getattr(settings, 'PIPELINE', {})
210+
if pipeline.get('PIPELINE_ENABLED', True) or not getattr(settings, 'REQUIRE_DEBUG', False):
211+
resource_path = pipeline_path
212+
else:
213+
resource_path = dev_path
214+
return xblock.runtime.local_resource_url(xblock, resource_path)

0 commit comments

Comments
 (0)