How to use the xblock.core.XBlock.handler function in XBlock

To help you get started, we’ve selected a few XBlock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github appsembler / xblock-video / video_xblock / mixins.py View on Github external
    @XBlock.handler
    def fetch_from_three_play_media(self, request, _suffix=''):
        """
        Proxy handler to hide real API url.

        Arguments:
            request (webob.Request): The request to handle
            suffix (string): not used
            query string: 'language_id=transcript_id'
        Returns:
            webob.Response: WebVTT transcripts wrapped in Response object.
        """
        lang_id, transcript_id = request.query_string.split('=')
        transcript = self.fetch_single_3pm_translation(transcript_data={'id': transcript_id, 'language_id': lang_id})
        if transcript is None:
            return Response()
        return Response(transcript.content, content_type='text/vtt')
github appsembler / xblock-video / video_xblock / video_xblock.py View on Github external
    @XBlock.handler
    def render_player(self, _request, _suffix=''):
        """
        View `student_view` loads this handler as an iframe to display actual video player.

        Arguments:
            _request (webob.Request): Request to handle. Imposed by `XBlock.handler`.
            _suffix (string): Slug used for routing. Imposed by `XBlock.handler`.
        Returns:
            Rendered html string as a Response (webob.Response).
        """
        player = self.get_player()
        save_state_url = self.runtime.handler_url(self, 'save_player_state')
        transcripts = render_resource(
            'static/html/transcripts.html',
            transcripts=self.route_transcripts()
        ).strip()
github ibleducation / jupyter-edx-grader-xblock / xblock_jupyter_graded / xblock_jupyter_graded.py View on Github external
    @XBlock.handler
    def handle_student_nb_upload(self, request, suffix=u''):
        """Handles uploading a student notebook"""
        log.info("Handling student nb upload for course: {}, xblock: {}"\
            .format(str(self.course_id), str(self.location)))
        # Handle empty file, wrong file type
        f = request.params['file']

        # Validate file upload
        error = self.validate_student_nb_upload(request)
        if error:
            return Response(body=json.dumps(error), 
                content_type="application/json", status=200);

        # Get User Info
        user_service = self.runtime.service(self, 'user')
        user = user_service.get_current_user()
github google / coursebuilder_xblock_module / cb-xblocks-core / cb_xblocks_core / problem.py View on Github external
    @xblock.core.XBlock.handler
    def wrapper(self, request, unused_suffix=''):

        before = self.get_progress()

        result = handler(self, request.POST)

        after = self.get_progress()

        result.update({
            'progress_changed': after != before,
            'progress_status': progress.Progress.to_js_status_str(after),
            'progress_detail': progress.Progress.to_js_detail_str(after),
        })

        # TODO(jorr): Security - use transforms dumps
        return webob.Response(
github appsembler / xblock-video / video_xblock / mixins.py View on Github external
    @XBlock.handler
    def download_transcript(self, request, _suffix=''):
        """
        Download a transcript.

        Arguments:
            request (webob.Request): Request to handle.
            suffix (string): Slug used for routing.
        Returns:
            File with the correct name.
        """
        trans_path = self.get_path_for(request.query_string)
        filename = self.get_file_name_from_path(trans_path)
        transcript = requests.get(request.host_url + request.query_string).text
        response = Response(transcript)
        headerlist = [
            ('Content-Type', 'text/plain'),
github appsembler / xblock-video / video_xblock / mixins.py View on Github external
    @XBlock.handler
    def validate_three_play_media_config(self, request, _suffix=''):
        """
        Handler to validate provided API credentials.

        Arguments:
            request (webob.Request):
            suffix (string): not used
        Returns:
            webob.Response: (json) {'isValid': true/false}
        """
        api_key = request.json.get('api_key')
        file_id = request.json.get('file_id')
        streaming_enabled = bool(int(request.json.get('streaming_enabled')))  # streaming_enabled is expected to be "1"

        is_valid = True
        success_message = _('Success')
github Kalyzee / knotes / videoknotes / videoknotes.py View on Github external
    @XBlock.handler
    def export_notes(self, request, suffix=''):
        """ Return an pdf export of user and public notes

        Returns:
            response

        """ 
        res = Response()
        student = self.__get_current_user()

        try:
            timecoded_data_set = self.__list_notes()
            timecoded_data_array = []

            for timecoded_data in timecoded_data_set:
                timecoded_data_array.append([timecoded_data.seconds, Paragraph(timecoded_data.content.replace('\n','<br>'), ParagraphStyle("Page"))])
github appsembler / xblock-video / video_xblock / video_xblock.py View on Github external
    @XBlock.handler
    def ui_dispatch(self, _request, suffix):
        """
        Dispatcher for a requests sent by dynamic Front-end components.

        Typical use case: Front-end wants to check with backend if it's ok to show certain part of UI.

        Arguments:
            _request (xblock.django.request.DjangoWebobRequest): Incoming request data. Not used.
            suffix (str): Slug used for routing.
        Returns:
             Response object, containing response data.
        """
        resp = {
            'success': True,
            'data': {}
        }
github edx / XBlock / xblock / core.py View on Github external
        @XBlock.handler
        @functools.wraps(func)
        def wrapper(self, request, suffix=''):
            """The wrapper function `json_handler` returns."""
            request_json = json.loads(request.body)
            response_json = json.dumps(func(self, request_json, suffix))
            return Response(response_json, content_type='application/json')
        return wrapper
github edx / XBlock / acid / acid / acid.py View on Github external
    @XBlock.handler
    def check_storage(self, request, suffix=''):
        """
        Verifies that scoped storage is working correctly, and that handler_urls
        are generated correctly by both the client- and server-side runtimes.

        Args:
            request (:class:`webob.Request`): The incoming request
            suffix (`str`): The suffix that the handler was called with
        """

        if 'SCOPE' not in request.GET:
            return FailureResponse("SCOPE is missing from query parameters")

        scope = request.GET['SCOPE']

        if 'QUERY' not in request.GET: