當前位置: 首頁>>代碼示例>>Python>>正文


Python XBlock.json_handler方法代碼示例

本文整理匯總了Python中xblock.core.XBlock.json_handler方法的典型用法代碼示例。如果您正苦於以下問題:Python XBlock.json_handler方法的具體用法?Python XBlock.json_handler怎麽用?Python XBlock.json_handler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xblock.core.XBlock的用法示例。


在下文中一共展示了XBlock.json_handler方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: publish_event

# 需要導入模塊: from xblock.core import XBlock [as 別名]
# 或者: from xblock.core.XBlock import json_handler [as 別名]
def publish_event(self, data, _suffix=''):
        """
        Handler to publish XBlock event from frontend. Called by JavaScript of `student_view`.

        Arguments:
            data (dict): Data from frontend on the event.
            _suffix (string): Slug used for routing. Imposed by `XBlock.json_handler`.
        Returns:
            Data on result (dict).
        """
        try:
            event_type = data.pop('eventType')
        except KeyError:
            return {'result': 'error', 'message': 'Missing eventType in JSON data'}

        self.runtime.publish(self, event_type, data)
        return {'result': 'success'} 
開發者ID:appsembler,項目名稱:xblock-video,代碼行數:19,代碼來源:video_xblock.py

示例2: authenticate_video_api_handler

# 需要導入模塊: from xblock.core import XBlock [as 別名]
# 或者: from xblock.core.XBlock import json_handler [as 別名]
def authenticate_video_api_handler(self, data, _suffix=''):
        """
        Xblock handler to authenticate to a video platform's API. Called by JavaScript of `studio_view`.

        Arguments:
            data (dict): Data from frontend, necessary for authentication (tokens, account id, etc).
            _suffix (str): Slug used for routing. Imposed by `XBlock.json_handler`.
        Returns:
            response (dict): Status messages key-value pairs.
        """
        # Fetch a token provided by a user before the save button was clicked.
        token = str(data)

        is_default_token = token == self.fields['token'].default  # pylint: disable=unsubscriptable-object
        is_youtube_player = str(self.player_name) != PlayerName.YOUTUBE  # pylint: disable=unsubscriptable-object
        if not token or (is_default_token and is_youtube_player):
            return {
                'error_message': "In order to authenticate to a video platform's API, "
                                 "please provide a Video API Token."
                }

        _auth_data, error_message = self.authenticate_video_api(token)
        if error_message:
            return {'error_message': error_message}
        return {'success_message': 'Successfully authenticated to the video platform.'} 
開發者ID:appsembler,項目名稱:xblock-video,代碼行數:27,代碼來源:video_xblock.py

示例3: dispatch

# 需要導入模塊: from xblock.core import XBlock [as 別名]
# 或者: from xblock.core.XBlock import json_handler [as 別名]
def dispatch(self, request, suffix):
        """
        Dispatch request to XBlock's player.

        Arguments:
            request (xblock.django.request.DjangoWebobRequest): Incoming request data.
            suffix (str): Slug used for routing. Imposed by `XBlock.json_handler`.
        Returns:
             Depending on player's `dispatch()` entry point, either info on video / Brightcove account or None value
             (when performing some action via Brightcove API) may be returned.
        """
        return self.get_player().dispatch(request, suffix) 
開發者ID:appsembler,項目名稱:xblock-video,代碼行數:14,代碼來源:video_xblock.py

示例4: upload_default_transcript_handler

# 需要導入模塊: from xblock.core import XBlock [as 別名]
# 或者: from xblock.core.XBlock import json_handler [as 別名]
def upload_default_transcript_handler(self, data, _suffix=''):
        """
        Upload a transcript, fetched from a video platform's API, to video xblock.

        Arguments:
            data (dict): Data from frontend on a default transcript to be fetched from a video platform.
            _suffix (str): Slug used for routing. Imposed by `XBlock.json_handler`.
        Returns:
            response (dict): Data on a default transcript, fetched from a video platform.

        """
        log.debug("Uploading default transcript with data: {}".format(data))
        player = self.get_player()
        video_id = player.media_id(self.href)
        lang_code = str(data.get(u'lang'))
        lang_label = str(data.get(u'label'))
        source = str(data.get(u'source', ''))
        sub_url = str(data.get(u'url'))

        reference_name = create_reference_name(lang_label, video_id, source)

        # Fetch text of single default transcript:
        unicode_subs_text = player.download_default_transcript(sub_url, lang_code)
        if not unicode_subs_text:
            return {'failure_message': _("Couldn't upload transcript text.")}

        if not player.default_transcripts_in_vtt:
            prepared_subs = self.convert_caps_to_vtt(caps=unicode_subs_text)
        else:
            prepared_subs = unicode_subs_text

        file_name, external_url = self.create_transcript_file(
            trans_str=prepared_subs, reference_name=reference_name
        )

        # Exceptions are handled on the frontend
        success_message = 'Successfully uploaded "{}".'.format(file_name)
        response = {
            'success_message': success_message,
            'lang': lang_code,
            'url': external_url,
            'label': lang_label,
            'source': source,
        }
        log.debug("Uploaded default transcript: {}".format(response))
        return response 
開發者ID:appsembler,項目名稱:xblock-video,代碼行數:48,代碼來源:video_xblock.py


注:本文中的xblock.core.XBlock.json_handler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。