How to use the xblock.core.XBlock 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 edx / XBlock / xblock / problem.py View on Github external
class InputBlock(XBlock):
    """Base class for blocks that accept inputs.

    """
    def submit(self, submission):
        """
        Called with the result of the javascript Block's submit() function.
        Returns any data, which is passed to the Javascript handle_submit
        function.

        """
        pass


@XBlock.tag("checker")
class CheckerBlock(XBlock):
    """Base class for blocks that check answers.

    """
    arguments = Dict(help="The arguments expected by `check`")

    def set_arguments_from_xml(self, node):
        """
        Set the `arguments` field from XML attributes based on `check` arguments.
        """
        # Introspect the .check() method, and collect arguments it expects.
        argspec = inspect.getargspec(self.check)
        arguments = {}
        for arg in argspec.args[1:]:
            arguments[arg] = node.attrib.pop(arg)
        self.arguments = arguments
github ibleducation / jupyter-edx-grader-xblock / xblock_jupyter_graded / xblock_jupyter_graded.py View on Github external
from xblock.core import XBlock
from xblock.fields import Scope, String, Integer, Float, Boolean, List
from xblock.fragment import Fragment
from xblockutils.studio_editable import StudioEditableXBlockMixin
from xblockutils.resources import ResourceLoader
from xmodule.studio_editable import StudioEditableBlock

from rest.urls import app_name

log = logging.getLogger(__name__)
loader = ResourceLoader(__name__)


@XBlock.needs("user")
class JupyterGradedXBlock(StudioEditableXBlockMixin, ScorableXBlockMixin,
        XBlock, StudioEditableBlock):

    # Makes LMS icon appear as a problem
    icon_class = "problem"

    # ------- External, Editable Fields -------
    display_name = String(
        display_name="Display Name", 
        default="Graded Jupyter Notebook",
        scope=Scope.settings,
        help="Name of this XBlock" 
    )

    instructions = String(
        help="Instructions displayed to Student",
        scope=Scope.content,
        display_name="Student Instructions",
github edx / XBlock / demo_xblocks / demo_xblocks / content.py View on Github external
"""Content-oriented XBlocks."""

from string import Template  # pylint: disable=W0402

from lxml import etree

from xblock.core import XBlock, String, Scope
from xblock.fragment import Fragment


class HelloWorldBlock(XBlock):
    """A simple block: just show some fixed content."""
    def fallback_view(self, view_name, context=None):  # pylint: disable=W0613
        """Provide a fallback view handler"""
        return Fragment(u"Hello, world!")


class HtmlBlock(XBlock):
    """Render content as HTML.

    The content can have $PLACEHOLDERS, which will be substituted with values
    from the context.

    """

    content = String(help="The HTML to display", scope=Scope.content, default=u"<b>DEFAULT</b>")
github appsembler / xblock-video / video_xblock / video_xblock.py View on Github external
from .exceptions import ApiClientError
from .fields import RelativeTime
from .mixins import ContentStoreMixin, LocationMixin, PlaybackStateMixin, SettingsMixin, TranscriptsMixin
from .settings import ALL_LANGUAGES
from .utils import (
    create_reference_name, filter_transcripts_by_source, normalize_transcripts,
    render_resource, render_template, resource_string, ugettext as _,
)
from .workbench.mixin import WorkbenchMixin

log = logging.getLogger(__name__)


class VideoXBlock(
        SettingsMixin, TranscriptsMixin, PlaybackStateMixin, LocationMixin,
        StudioEditableXBlockMixin, ContentStoreMixin, WorkbenchMixin, XBlock
):
    """
    Main VideoXBlock class, responsible for saving video settings and rendering it for students.

    VideoXBlock only provide a storage facilities for fields data, but not
    decide what fields to show to user. `BaseVideoPlayer` and it's subclassess
    declare what fields are required for proper configuration of a video.
    See `BaseVideoPlayer.basic_fields` and `BaseVideoPlayer.advanced_fields`.
    """

    icon_class = "video"

    display_name = String(
        default=_('Video'),
        display_name=_('Component Display Name'),
        help=_('The name students see. This name appears in the course ribbon and as a header for the video.'),
github appsembler / xblock-video / video_xblock / mixins.py View on Github external
    @XBlock.handler
    def srt_to_vtt(self, request, _suffix=''):
        """
        Fetch raw transcripts, convert them into WebVTT format and return back.

        Path to raw transcripts is passed in as `request.query_string`.

        Arguments:
            request (webob.Request): The request to handle
            suffix (string): The remainder of the url, after the handler url prefix, if available.
        Returns:
            webob.Response: WebVTT transcripts wrapped in Response object.
        """
        caps_path = request.query_string
        caps = requests.get(request.host_url + caps_path).text
        return Response(self.convert_caps_to_vtt(caps))