How to use the xblock.core.XBlock.needs 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 google / coursebuilder_xblock_module / cb-xblocks-core / cb_xblocks_core / problem.py View on Github external
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(
            json.dumps(result, cls=xmodule.capa_base.ComplexEncoder),
            content_type='application/json')
    return wrapper


@xblock.core.XBlock.needs('i18n')
class ProblemBlock(xblock.core.XBlock, xmodule.capa_base.CapaMixin):

    def __init__(self, runtime, field_data, scope_ids):
        extras = RuntimeExtras(self, runtime)
        runtime = xblock.runtime.ObjectAggregator(extras, runtime)

        super(ProblemBlock, self).__init__(runtime, field_data, scope_ids)

        self.close_date = None
        self.close_date = None

        if self.seed is None:
            self.choose_new_seed()

        self.lcp = self.new_lcp(self.get_state_for_lcp())
github google / coursebuilder_xblock_module / cb-xblocks-core / cb_xblocks_core / cb_xblocks_core.py View on Github external
'nav_items': [
                NavItem(child_id, self.runtime) for child_id in self.children],
            'children': child_frags,
            'position': self.position}
        frag.add_content(template.render(template_values))

        return frag

    @XBlock.json_handler
    def on_select(self, data, suffix=''):
        self.position = data.get('position', 0)
        self.runtime.publish(self, {'position': self.position})
        return {'position': self.position}


@XBlock.needs('jinja')
class VerticalBlock(XBlock):
    """An XBlock which presents its children in a vertical list.

    See xmodule.vertical_module.VerticalModule in
    https://github.com/edx/edx-platform.
    """

    display_name = String(default=None, scope=Scope.content)

    has_children = True

    def __init__(self, *args, **kwargs):
        super(VerticalBlock, self).__init__(*args, **kwargs)
        self.templates_dirs = [os.path.join(os.path.dirname(__file__), 'templates')]
        self.get_template = self.runtime.service(self, 'jinja')
github eduNEXT / flow-control-xblock / flow_control / flow.py View on Github external
"value": "has_null"}
    ]


def n_all(iterable):
    """
    This iterator has the same logic of the function all() for an array.
    But it only responds to the existence of None and not False
    """
    for element in iterable:
        if element is None:
            return False
    return True


@XBlock.needs("i18n")
@XBlock.needs("user")
# pylint: disable=too-many-ancestors
class FlowCheckPointXblock(StudioEditableXBlockMixin, XBlock):
    """ FlowCheckPointXblock allows to take different
    learning paths based on a certain condition status """

    display_name = String(
        display_name="Display Name",
        scope=Scope.settings,
        default="Flow Control"
    )

    action = String(display_name="Action",
                    help="Select the action to be performed "
                    "when the condition is met",
                    scope=Scope.content,
github appsembler / xblock-video / video_xblock / mixins.py View on Github external
is_valid = False
            return Response(json={'isValid': is_valid, 'message': invalid_message})

        feedback, transcripts_list = self.get_3pm_transcripts_list(file_id, api_key)

        if transcripts_list and feedback['status'] is Status.success:
            message = success_message
            is_valid = True
        else:
            message = feedback['message']
            is_valid = False

        return Response(json={'isValid': is_valid, 'message': message})


@XBlock.needs('modulestore')
class PlaybackStateMixin(XBlock):
    """
    PlaybackStateMixin encapsulates video-playback related data.

    These fields are not visible to end-user.
    """

    current_time = Float(
        default=0,
        scope=Scope.user_state,
        help='Seconds played back after the start'
    )

    playback_rate = Float(
        default=1,
        scope=Scope.preferences,
github ibleducation / jupyter-edx-grader-xblock / xblock_jupyter_graded / xblock_jupyter_graded.py View on Github external
from scorable import ScorableXBlockMixin, Score

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",
github eduNEXT / flow-control-xblock / flow_control / flow.py View on Github external
]


def n_all(iterable):
    """
    This iterator has the same logic of the function all() for an array.
    But it only responds to the existence of None and not False
    """
    for element in iterable:
        if element is None:
            return False
    return True


@XBlock.needs("i18n")
@XBlock.needs("user")
# pylint: disable=too-many-ancestors
class FlowCheckPointXblock(StudioEditableXBlockMixin, XBlock):
    """ FlowCheckPointXblock allows to take different
    learning paths based on a certain condition status """

    display_name = String(
        display_name="Display Name",
        scope=Scope.settings,
        default="Flow Control"
    )

    action = String(display_name="Action",
                    help="Select the action to be performed "
                    "when the condition is met",
                    scope=Scope.content,
                    default="display_message",
github microsoft / xblock-azure-media-services / azure_media_services / ams.py View on Github external
from azure_video_pipeline.media_service import LocatorTypes
    from azure_video_pipeline.utils import (
        get_azure_config, get_media_service_client, get_captions_info, get_video_info
    )
except ImportError:
    APP_AZURE_VIDEO_PIPELINE = False


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

# According to edx-platform vertical xblocks
CLASS_PRIORITY = ['video']


@XBlock.needs('i18n')
class AMSXBlock(StudioEditableXBlockMixin, XBlock):
    """
    The xBlock to play videos from Azure Media Services.
    """

    RESOURCE = 'https://rest.media.azure.net'

    display_name = String(
        display_name=_("Display Name"),
        help=_(
            "Enter the name that students see for this component. "
            "Analytics reports may also use the display name to identify this component."
        ),
        scope=Scope.settings,
        default=_("Azure Media Services Video Player"),
    )