How to use the xblock.fields.Integer 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
import random
import string  # pylint: disable=W0402
import time

from xblock.core import XBlock
from xblock.fields import Integer, Scope, String, Any, Boolean, Dict
from xblock.run_script import run_script
from xblock.fragment import Fragment


class ProblemBlock(XBlock):
    """A generalized container of InputBlocks and Checkers.

    """
    script = String(help="Python code to compute values", scope=Scope.content, default="")
    seed = Integer(help="Random seed for this student", scope=Scope.user_state, default=0)
    problem_attempted = Boolean(help="Has the student attempted this problem?", scope=Scope.user_state, default=False)
    has_children = True

    @classmethod
    def parse_xml(cls, node, runtime, keys):
        block = runtime.construct_xblock_from_class(cls, keys)

        # Find 
github open-craft / xblock-simplevideo / simplevideo.py View on Github external
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 edx / XBlock / thumbs / thumbs / thumbs.py View on Github external
import logging
log = logging.getLogger(__name__)


class ThumbsBlock(XBlock):
    """
    An XBlock with thumbs-up/thumbs-down voting.

    Vote totals are stored for all students to see.  Each student is recorded
    as has-voted or not.

    This demonstrates multiple data scopes and ajax handlers.

    """

    upvotes = Integer(help="Number of up votes", default=0, scope=Scope.user_state_summary)
    downvotes = Integer(help="Number of down votes", default=0, scope=Scope.user_state_summary)
    voted = Boolean(help="Has this student voted?", default=False, scope=Scope.user_state)

    def student_view(self, context=None):  # pylint: disable=W0613
        """
        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.
        """

        # Load the HTML fragment from within the package and fill in the template
        html_str = pkg_resources.resource_string(__name__, "static/html/thumbs.html")
        frag = Fragment(unicode(html_str).format(self=self))
github ibleducation / jupyter-edx-grader-xblock / xblock_jupyter_graded / xblock_jupyter_graded.py View on Github external
instructions = String(
        help="Instructions displayed to Student",
        scope=Scope.content,
        display_name="Student Instructions",
        multiline_editor=True,
    )

    max_attempts = Integer(
        help="Max number of allowed submissions (0 = unlimited)",
        scope=Scope.settings,
        display_name="Allowed Submissions",
        default=0
    )

    cell_timeout = Integer(
        help="Max seconds to wait for each cell to execute",
        scope=Scope.settings,
        display_name="Cell Timeout (s)",
        default=15
    )

    max_file_size = Integer(
        help="Max allowable file size of student uploaded file (Bytes)",
        scope=Scope.settings,
        display_name="Max File Size (B)",
        default=None
    )

    allow_network = Boolean (
        help="If True, allows network access from student notebook",
        scope=Scope.settings,
github raccoongang / edx_xblock_scorm / scormxblock / scormxblock.py View on Github external
)
    weight = Float(
        default=1,
        scope=Scope.settings
    )
    has_score = Boolean(
        display_name=_("Scored"),
        help=_("Select False if this component will not receive a numerical score from the Scorm"),
        default=True,
        scope=Scope.settings
    )
    icon_class = String(
        default="video",
        scope=Scope.settings,
    )
    width = Integer(
        display_name=_("Display Width (px)"),
        help=_('Width of iframe, if empty, the default 100%'),
        scope=Scope.settings
    )
    height = Integer(
        display_name=_("Display Height (px)"),
        help=_('Height of iframe'),
        default=450,
        scope=Scope.settings
    )

    has_author_view = True

    def resource_string(self, path):
        """Handy helper for getting resources from our kit."""
        data = pkg_resources.resource_string(__name__, path)
github oppia / oppia / integrations / openedx_xblock_20150715_v0.0.0 / xblock-oppia / oppia / oppia.py View on Github external
"""
    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)
        return data.decode("utf8")

    def student_view(self, context=None):
        """
        The primary view of the OppiaXBlock, shown to students
github edx / XBlock / thumbs / thumbs / thumbs.py View on Github external
log = logging.getLogger(__name__)


class ThumbsBlock(XBlock):
    """
    An XBlock with thumbs-up/thumbs-down voting.

    Vote totals are stored for all students to see.  Each student is recorded
    as has-voted or not.

    This demonstrates multiple data scopes and ajax handlers.

    """

    upvotes = Integer(help="Number of up votes", default=0, scope=Scope.user_state_summary)
    downvotes = Integer(help="Number of down votes", default=0, scope=Scope.user_state_summary)
    voted = Boolean(help="Has this student voted?", default=False, scope=Scope.user_state)

    def student_view(self, context=None):  # pylint: disable=W0613
        """
        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.
        """

        # Load the HTML fragment from within the package and fill in the template
        html_str = pkg_resources.resource_string(__name__, "static/html/thumbs.html")
        frag = Fragment(unicode(html_str).format(self=self))

        # Load the CSS and JavaScript fragments from within the package
github edx / XBlock / demo_xblocks / demo_xblocks / slider.py View on Github external
WARNING: This is an experimental module, subject to future change or removal.
"""

import json
from webob import Response

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


class Slider(XBlock):
    """Base XBlock with a slider interface."""
    min_value = Integer(help="Minimum value", default=0, scope=Scope.content)
    max_value = Integer(help="Maximum value", default=100, scope=Scope.content)
    value = Integer(help="Student value", default=0, scope=Scope.user_state)

    def student_view(self, context):  # pylint: disable=W0613
        """Provide the default student view."""
        html = SLIDER_TEMPLATE.format(min=self.min_value,
                                      max=self.max_value,
                                      val=self.value)
        frag = Fragment(html)
        frag.add_css("input[type=range] { width=100px; }")
        frag.add_javascript(SLIDER_JS)
        frag.initialize_js('Slider')

        return frag

    def update(self, request):
        """Update upon request."""
        data = json.loads(request.body)
github ibleducation / jupyter-edx-grader-xblock / xblock_jupyter_graded / xblock_jupyter_graded.py View on Github external
max_attempts = Integer(
        help="Max number of allowed submissions (0 = unlimited)",
        scope=Scope.settings,
        display_name="Allowed Submissions",
        default=0
    )

    cell_timeout = Integer(
        help="Max seconds to wait for each cell to execute",
        scope=Scope.settings,
        display_name="Cell Timeout (s)",
        default=15
    )

    max_file_size = Integer(
        help="Max allowable file size of student uploaded file (Bytes)",
        scope=Scope.settings,
        display_name="Max File Size (B)",
        default=None
    )

    allow_network = Boolean (
        help="If True, allows network access from student notebook",
        scope=Scope.settings,
        display_name="Network Allowed",
        default=False
    )

    allow_graded_dl = Boolean (
        help="If True, allows student to download .html version of their autograded notebook",
        scope=Scope.settings,
github ibleducation / jupyter-edx-grader-xblock / xblock_jupyter_graded / xblock_jupyter_graded.py View on Github external
# ------- 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",
        multiline_editor=True,
    )

    max_attempts = Integer(
        help="Max number of allowed submissions (0 = unlimited)",
        scope=Scope.settings,
        display_name="Allowed Submissions",
        default=0
    )

    cell_timeout = Integer(
        help="Max seconds to wait for each cell to execute",
        scope=Scope.settings,
        display_name="Cell Timeout (s)",
        default=15
    )

    max_file_size = Integer(
        help="Max allowable file size of student uploaded file (Bytes)",
        scope=Scope.settings,