How to use the xblock.fields.Scope.content 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 / appengine_xblock_runtime / tests / test_runtime.py View on Github external
def test_html_block(self):
        """Test persistence of fields in content scope."""
        usage_id = self.runtime.parse_xml_string(
            'text', self.id_generator)
        block = self.runtime.get_block(usage_id)

        key = xblock.runtime.KeyValueStore.Key(
            scope=xblock.fields.Scope.content,
            user_id=None,
            block_scope_id=block.scope_ids.def_id,
            field_name='content')

        self.assertEqual('text', store.KeyValueStore().get(key))
github edx / XBlock / xblock / problem.py View on Github external
return result

    def submit(self, submission):
        self.student_input = submission[0]['value']
        if self.input_type == 'int':
            try:
                self.student_input = int(submission[0]['value'])
            except ValueError:
                return {'error': '"%s" is not an integer' % self.student_input}


class EqualityCheckerBlock(CheckerBlock):
    """An XBlock that checks the equality of two student data fields."""

    # Content: the problem will hook us up with our data.
    content = String(help="Message describing the equality test", scope=Scope.content, default="Equality test")

    # Student data
    left = Any(scope=Scope.user_state)
    right = Any(scope=Scope.user_state)
    attempted = Boolean(scope=Scope.user_state)

    def problem_view(self, context=None):
        """Renders the problem view.

        The view is specific to whether or not this problem was attempted, and, if so,
        if it was answered correctly.

        """
        correct = self.left == self.right

        # TODO: I originally named this class="data", but that conflicted with
github Kalyzee / knotes / videoknotes / videoknotes.py View on Github external
from .models import KNoteList, KNote



class VideoKNotesBlock(XBlock):
    """
    VideoKNotesBlock allows the users to create comments timecoded (means comments can be located in time).
    Users can export all visible comments as CSV.
    Owners can share their comment when they mark them as public.
    Student can comment as private.
    """


    """Video URL
    """ 
    href = String(help="Video URL", default="http://www.dailymotion.com/video/x2e4j6u", scope=Scope.content)

    def student_view(self, context):
        """
        Show all knotes for the current user and the owner(s) which are in public state.
        """
        student = self.__get_current_user()

        comment = KNoteList.objects.get_or_create_note_list(student, self.__get_xblock_key())

            
        """Find all knotes ordered by seconds"""
        timecoded_data_set = self.__list_notes()
        timecoded_data_array = []
        for timecoded_data in timecoded_data_set:
            """Convert Knote objects (python) to Knote objects (Javascript) """
            obj = {"time": timecoded_data.seconds, "value":timecoded_data.content, "user": self.scope_ids.user_id , "public": timecoded_data.is_public, "mine": (self.scope_ids.user_id == timecoded_data.timecoded_comment.user.pk) , "id": timecoded_data.id}
github oppia / oppia / integrations / openedx_xblock_20150715_v0.0.0 / xblock-oppia / oppia / oppia.py View on Github external
from xblock.fields import Scope, Integer, String
from xblock.fragment import Fragment


class OppiaXBlock(XBlock):
    """
    An XBlock providing an embedded Oppia exploration.
    """

    # Note: These fields are defined on the class, and can be accessed in the
    # code as self..

    oppiaid = String(
        help="ID of the Oppia exploration to embed",
        default=None,
        scope=Scope.content)
    src = String(
        help="Source URL of the site",
        default="https://www.oppia.org",
        scope=Scope.content)
    width = Integer(
        help="Width of the embedded exploration",
        default=700,
        scope=Scope.content)
    height = Integer(
        help="Height of the embedded exploration",
        default=500,
        scope=Scope.content)

    def resource_string(self, path):
        """Handy helper for getting resources from our kit."""
        data = pkg_resources.resource_string(__name__, path)
github open-craft / xblock-simplevideo / simplevideo.py View on Github external
import requests

from urlparse import urlparse

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


class SimpleVideoBlock(XBlock):
    """
    An XBlock providing oEmbed capabilities for video (currently only supporting Vimeo)
    """

    href = String(help="URL of the video page at the provider", default=None, scope=Scope.content)
    maxwidth = Integer(help="Maximum width of the video", default=800, scope=Scope.content)
    maxheight = Integer(help="Maximum height of the video", default=450, scope=Scope.content)
    watched_count = Integer(help="The number of times the student watched the video", default=0, scope=Scope.user_state)

    def student_view(self, context):
        """
        Create a fragment used to display the XBlock to a student.
        `context` is a dictionary used to configure the display (unused)

        Returns a `Fragment` object specifying the HTML, CSS, and JavaScript
        to display.
        """
        provider, embed_code = self.get_embed_code_for_url(self.href)

        # Load the HTML fragment from within the package and fill in the template
        html_str = pkg_resources.resource_string(__name__, "static/html/simplevideo.html")
        frag = Fragment(unicode(html_str).format(self=self, embed_code=embed_code))
github ibleducation / jupyter-edx-viewer-xblock / xblock_jupyter_viewer / xblock_jupyter_viewer.py View on Github external
log = logging.getLogger(__name__)


class JupyterViewerXBlock(XBlock, StudioEditableXBlockMixin):
    """iframe used with endpoint to render full/section of jupyter notebook"""

    display_name = String(
        display_name="Display Name", default="Jupyter Notebook Viewer",
        scope=Scope.settings,
        help="Name of this XBlock" 
    )

    jupyter_url = String(
        help="URL to the .ipynb File",
        scope=Scope.content,
        display_name="Notebook URL",
        default="http://path/to/file.ipynb"
    )

    image_url = String(
        help="(Optional) Absolute URL to images root (http://.../)",
        scope=Scope.content,
        display_name="Image Root URL",
        default=""
    )

    start_tag = String(
        help="(Optional) Finds first occurrence of this text and renders notebook starting in this cell",
        scope=Scope.content,
        display_name="Start Tag",
        default=""
github appsembler / xblock-video / video_xblock / video_xblock.py View on Github external
"""
    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.'),
        scope=Scope.content,
    )

    href = String(
        default='',
        display_name=_('Video URL'),
        help=_('URL of the video page. E.g. https://example.wistia.com/medias/12345abcde'),
        scope=Scope.content
    )

    download_video_allowed = Boolean(
        default=False,
        scope=Scope.content,
        display_name=_('Video Download Allowed'),
        help=_(
            "Allow students to download this video if they cannot use the edX video player."
            " A link to download the file appears below the video."
github eduNEXT / flow-control-xblock / flow_control / flow.py View on Github external
operator = String(display_name="Comparison type",
                      help="Select an operator for the condition",
                      scope=Scope.content,
                      default='eq',
                      values_provider=_operators_generator)

    ref_value = Integer(help="Enter the value to be used in "
                        "the comparison. (From 0 to 100)",
                        default=0,
                        scope=Scope.content,
                        display_name="Score percentage")

    tab_to = Integer(help="Number of unit tab to redirect to. (1, 2, 3...)",
                     default=1,
                     scope=Scope.content,
                     display_name="Tab to redirect to")

    target_url = String(help="URL to redirect to, supports relative "
                        "or absolute urls",
                        scope=Scope.content,
                        display_name="URL to redirect to")

    target_id = String(help="Unit identifier to redirect to (Location id)",
                       scope=Scope.content,
                       display_name="Unit identifier to redirect to")

    message = String(help="Message for the learners to view "
                     "when the condition is met",
                     scope=Scope.content,
                     default='',
                     display_name="Message",
github edx / XBlock / xblock / core.py View on Github external
"""
        Use `node` to construct a new block.
        """
        block = runtime.construct_xblock_from_class(cls, keys)

        # The base implementation: child nodes become child blocks.
        for child in node:
            block.runtime.add_node_as_child(block, child)

        # Attributes become fields.
        for name, value in node.items():
            if name in block.fields:
                setattr(block, name, value)

        # Text content becomes "content", if such a field exists.
        if "content" in block.fields and block.fields["content"].scope == Scope.content:
            text = node.text
            if text:
                text = text.strip()
                if text:
                    block.content = text

        return block
github appsembler / xblock-video / video_xblock / video_xblock.py View on Github external
),
        display_name=_("Video Stop Time"),
        scope=Scope.content,
        default=datetime.timedelta(seconds=0)
    )

    handout = String(
        default='',
        scope=Scope.content,
        display_name=_('Upload handout'),
        help=_('You can upload handout file for students')
    )

    download_transcript_allowed = Boolean(
        default=False,
        scope=Scope.content,
        display_name=_('Download Transcript Allowed'),
        help=_(
            "Allow students to download the timed transcript. A link to download the file appears below the video."
            " By default, the transcript is an .vtt or .srt file. If you want to provide the transcript for download"
            " in a different format, upload a file by using the Upload Handout field."
        ),
        resettable_editor=False
    )

    default_transcripts = String(
        default='',
        scope=Scope.content,
        display_name=_('Default Timed Transcript'),
        help=_(
            'Default transcripts are uploaded automatically from a video platform '
            'to the list of available transcripts.<br>'