Skip to content

Commit 5309eee

Browse files
committed
feat: Adds the Video XBlock code extracted from the edx-platform
1 parent b946516 commit 5309eee

24 files changed

Lines changed: 3812 additions & 562 deletions

‎xblocks_contrib/video/ajax_handler_mixin.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
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+
from xblock.core import XBlock
2+
from webob.multidict import MultiDict
3+
from webob import Response
34

4-
class XModuleToXBlockMixin:
5+
class AjaxHandlerMixin:
56
"""
6-
Common code needed by XModule and XBlocks converted from XModules.
7+
Mixin that provides AJAX handling for Video XBlock
78
"""
89
@property
910
def ajax_url(self):
1011
"""
1112
Returns the URL for the ajax handler.
1213
"""
13-
return self.runtime.handler_url(self, 'xmodule_handler', '', '').rstrip('/?')
14+
return self.runtime.handler_url(self, 'ajax_handler', '', '').rstrip('/?')
1415

1516
@XBlock.handler
16-
def xmodule_handler(self, request, suffix=None):
17+
def ajax_handler(self, request, suffix=None):
1718
"""
18-
XBlock handler that wraps `handle_ajax`
19+
XBlock handler that wraps `ajax_handler`
1920
"""
2021
class FileObjForWebobFiles:
2122
"""

‎xblocks_contrib/video/bumper_utils.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# NOTE: Code has been copied from the following source files
2-
# https://github.com/openedx/edx-platform/blob/master/xmodule/video_block/bumper_utils.py
31
"""
42
Utils for video bumper
53
"""

‎xblocks_contrib/video/cache_utils.py‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
# NOTE: Code has been copied from the following source files
2-
# https://github.com/openedx/edx-platform/blob/master/openedx/core/lib/cache_utils.py
3-
"""
4-
Utilities related to caching.
5-
"""
6-
7-
81
import itertools
9-
102
import wrapt
11-
from django.db.models.signals import post_save, post_delete
3+
124
from django.utils.encoding import force_str
135

146
from edx_django_utils.cache import RequestCache

‎xblocks_contrib/video/constants.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Constants used by DjangoXBlockUserService
3+
"""
4+
5+
# This is the view that will be rendered to display the XBlock in the LMS.
6+
# It will also be used to render the block in "preview" mode in Studio, unless
7+
# the XBlock also implements author_view.
8+
STUDENT_VIEW = 'student_view'
9+
10+
# This is the view that will be rendered to display the XBlock in the LMS for unenrolled learners.
11+
# Implementations of this view should assume that a user and user data are not available.
12+
PUBLIC_VIEW = 'public_view'
13+
14+
# The personally identifiable user ID.
15+
ATTR_KEY_USER_ID = 'edx-platform.user_id'
16+
# The country code determined from the user's request IP address.
17+
ATTR_KEY_REQUEST_COUNTRY_CODE = 'edx-platform.request_country_code'

‎xblocks_contrib/video/content.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# NOTE: Original code has been copied from the following file:
2-
# https://github.com/openedx/edx-platform/blob/farhan/extract-video-xblock/xmodule/contentstore/content.py#L28
1+
from opaque_keys import InvalidKeyError
2+
from opaque_keys.edx.keys import AssetKey
3+
from opaque_keys.edx.locator import AssetLocator
34

4-
5-
class StaticContent: # lint-amnesty, pylint: disable=missing-class-docstring
5+
"""
6+
Methods of this class has been copied from the
7+
StaticContent class in edx-platform/xmodule/contentstore/content.py
8+
"""
9+
class VideoBlockStaticContent: # lint-amnesty, pylint: disable=missing-class-docstring
610
def __init__(self, loc, name, content_type, data, last_modified_at=None, thumbnail_location=None, import_path=None,
711
length=None, locked=False, content_digest=None):
812
self.location = loc
@@ -19,7 +23,8 @@ def __init__(self, loc, name, content_type, data, last_modified_at=None, thumbna
1923
self.content_digest = content_digest
2024

2125
@staticmethod
22-
def compute_location(course_key, path, revision=None, is_thumbnail=False): # lint-amnesty, pylint: disable=unused-argument
26+
def compute_location(course_key, path, revision=None,
27+
is_thumbnail=False): # lint-amnesty, pylint: disable=unused-argument
2328
"""
2429
Constructs a location object for static content.
2530

‎xblocks_contrib/video/exceptions.py‎

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,3 @@ class TranscriptsGenerationException(Exception):
99

1010
class TranscriptNotFoundError(Exception):
1111
pass
12-
13-
# # lint-amnesty, pylint: disable=missing-module-docstring
14-
# class InvalidDefinitionError(Exception):
15-
# pass
16-
17-
18-
class NotFoundError(Exception):
19-
pass
20-
21-
22-
# class ProcessingError(Exception):
23-
# '''
24-
# An error occurred while processing a request to the XModule.
25-
# For example: if an exception occurs while checking a capa problem.
26-
# '''
27-
# pass # lint-amnesty, pylint: disable=unnecessary-pass
28-
29-
30-
# class InvalidVersionError(Exception):
31-
# """
32-
# Tried to save an item with a location that a store cannot support (e.g., draft version
33-
# for a non-leaf node)
34-
# """
35-
# def __init__(self, location):
36-
# super().__init__()
37-
# self.location = location
38-
39-
40-
# class SerializationError(Exception):
41-
# """
42-
# Thrown when a module cannot be exported to XML
43-
# """
44-
# def __init__(self, location, msg):
45-
# super().__init__(msg)
46-
# self.location = location
47-
48-
49-
# class UndefinedContext(Exception):
50-
# """
51-
# Tried to access an xmodule field which needs a different context (runtime) to have a value.
52-
# """
53-
# pass # lint-amnesty, pylint: disable=unnecessary-pass
54-
55-
56-
# class HeartbeatFailure(Exception):
57-
# """
58-
# Raised when heartbeat fails.
59-
# """
60-
61-
# def __init__(self, msg, service):
62-
# """
63-
# In addition to a msg, provide the name of the service.
64-
# """
65-
# self.service = service
66-
# super().__init__(msg)
67-
68-
69-
class ServiceUnavailable(Exception):
70-
"""
71-
This error is raised if the service backing this client is currently unavailable.
72-
"""

‎xblocks_contrib/video/mixin.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# NOTE: Code has been copied from the following source files
2-
# https://github.com/openedx/edx-platform/blob/master/openedx/core/lib/license/mixin.py
31
"""
4-
License mixin for XBlocks and XModules
2+
License mixin for XBlocks
53
"""
64

75
from xblock.core import XBlockMixin

0 commit comments

Comments
 (0)