Ejemplo n.º 1
0
    def lti_launch_handler(self, request, suffix=''):  # pylint: disable=unused-argument
        """
        XBlock handler for launching the LTI provider.

        Displays a form which is submitted via Javascript
        to send the LTI launch POST request to the LTI
        provider.

        Arguments:
            request (xblock.django.request.DjangoWebobRequest): Request object for current HTTP request
            suffix (unicode): Request path after "lti_launch_handler/"

        Returns:
            webob.response: HTML LTI launch form
        """

        self.lti_consumer = FUNLtiConsumer(self)
        self.lti_parameters = self.lti_consumer.get_signed_lti_parameters()
        pprint(self.lti_parameters)
        loader = ResourceLoader(__name__)
        context = self._get_context_for_template()
        context.update({'lti_parameters': self.lti_parameters})
        template = loader.render_mako_template('static/html/lti_launch.html',
                                               context)
        return Response(template, content_type='text/html')
Ejemplo n.º 2
0
    def student_view(self, context):
        """
        XBlock student view of this component.

        Makes a request to `lti_launch_handler` either
        in an iframe or in a new window depending on the
        configuration of the instance of this XBlock

        Arguments:
            context (dict): XBlock context

        Returns:
            xblock.fragment.Fragment: XBlock HTML fragment
        """
        fragment = Fragment()
        loader = ResourceLoader(__name__)
        context.update(self._get_context_for_template())
        fragment.add_content(
            loader.render_mako_template('/templates/html/student.html',
                                        context))
        fragment.add_css(loader.load_unicode('static/css/student.css'))
        fragment.add_javascript(
            loader.load_unicode('static/js/xblock_lti_consumer.js'))
        fragment.initialize_js('LtiConsumerXBlock')
        return fragment
Ejemplo n.º 3
0
 def author_view(self, context):
     fragment = Fragment()
     loader = ResourceLoader(__name__)
     context.update(self._get_context_for_template())
     fragment.add_content(
         loader.render_mako_template('/templates/author.html', context))
     return fragment
Ejemplo n.º 4
0
 def student_view(self, context):
     fragment = Fragment()
     lti_loader = ResourceLoader('lti_consumer')
     loader = ResourceLoader(__name__)
     context.update(self._get_context_for_template())
     fragment.add_content(
         loader.render_mako_template('/templates/student.html', context))
     fragment.add_css(loader.load_unicode('static/css/student.css'))
     fragment.add_javascript(
         lti_loader.load_unicode('static/js/xblock_lti_consumer.js'))
     fragment.initialize_js('LtiConsumerXBlock')
     return fragment
Ejemplo n.º 5
0
    def student_view(self, context):
        """
        LMS and CMS view for configurable_lti_consumer.
        Will make a post request to lti_launch_handler view with
        LTI parameters and open response in an iframe or a new window
        depending on the xblock instance configuration.
        Arguments:
            context (dict): XBlock context
        Returns:
            web_fragment.fragment.Fragment: XBlock HTML fragment
        """
        fragment = Fragment()
        configurable_lti_consumer_loader = ResourceLoader(__name__)
        lti_consumer_loader = ResourceLoader(
            "lti_consumer")  # ressource loader of inherited lti_consumer
        context.update(self._get_context_for_template())
        fragment.add_css(
            lti_consumer_loader.load_unicode("static/css/student.css"))
        fragment.add_javascript(
            lti_consumer_loader.load_unicode(
                "static/js/xblock_lti_consumer.js"))

        configuration = self.get_configuration(self.launch_url)

        # Automatic resizing
        if configuration.get("automatic_resizing"):
            context["automatic_resizing"] = configuration["automatic_resizing"]
            fragment.add_javascript(
                configurable_lti_consumer_loader.load_unicode(
                    "static/js/vendor/iframeResizer.min.js"))
        else:
            context["automatic_resizing"] = None

        # Inline ratio
        context["inline_ratio"] = configuration.get("inline_ratio", None)

        fragment.add_javascript(
            configurable_lti_consumer_loader.load_unicode(
                "static/js/configurable_xblock_lti_consumer.js"))

        json_args = {"element_id": context["element_id"]}
        fragment.initialize_js(
            "configurableLTIConsumerXblockIframeResizerInit",
            json_args=json_args)

        fragment.add_content(
            configurable_lti_consumer_loader.render_mako_template(
                "/templates/html/student.html", context))
        return fragment
Ejemplo n.º 6
0
 def student_view(self, context):
     fragment = Fragment()
     lti_loader = ResourceLoader('lti_consumer')
     loader = ResourceLoader(__name__)
     context = self._get_context_for_template()
     fragment.add_content(
         loader.render_mako_template('/templates/student.html', context))
     fragment.add_css(loader.load_unicode('static/css/student.css'))
     fragment.add_javascript(
         lti_loader.load_unicode('static/js/xblock_lti_consumer.js'))
     fragment.initialize_js('LtiConsumerXBlock')
     from .models import LaunchLog
     LaunchLog.update(self.runtime.user_id, self.location,
                      self.launch_settings['managed'])
     return fragment
Ejemplo n.º 7
0
    def student_view(self, context=None):
        """
        The primary view of the FUNGlowblXBlock, shown to students
        when viewing courses.
        """
        fragment = Fragment()
        loader = ResourceLoader(__name__)
        context.update(self._get_context_for_template())

        logo = self.runtime.local_resource_url(self,
                                               'public/img/logo-glowbl.png')
        context.update({'logo': logo})

        fragment.add_content(
            loader.render_mako_template('static/html/fun_glowbl.html',
                                        context))
        fragment.add_css(loader.load_unicode('static/css/fun_glowbl.css'))
        fragment.add_javascript(
            self.resource_string("static/js/src/fun_glowbl.js"))
        fragment.initialize_js('FUNGlowblXBlock')
        return fragment
Ejemplo n.º 8
0
    def lti_launch_handler(self, request, suffix=''):  # pylint: disable=unused-argument
        """
        XBlock handler for launching the LTI provider.

        Displays a form which is submitted via Javascript
        to send the LTI launch POST request to the LTI
        provider.

        Arguments:
            request (xblock.django.request.DjangoWebobRequest): Request object for current HTTP request
            suffix (unicode): Request path after "lti_launch_handler/"

        Returns:
            webob.response: HTML LTI launch form
        """
        lti_consumer = LtiConsumer(self)
        lti_parameters = lti_consumer.get_signed_lti_parameters()
        loader = ResourceLoader(__name__)
        context = self._get_context_for_template()
        context.update({'lti_parameters': lti_parameters})
        template = loader.render_mako_template('/templates/html/lti_launch.html', context)
        return Response(template, content_type='text/html')
Ejemplo n.º 9
0
    def student_view(self, context):
        """
        XBlock student view of this component.

        Makes a request to `lti_launch_handler` either
        in an iframe or in a new window depending on the
        configuration of the instance of this XBlock

        Arguments:
            context (dict): XBlock context

        Returns:
            xblock.fragment.Fragment: XBlock HTML fragment
        """
        fragment = Fragment()
        loader = ResourceLoader(__name__)
        context.update(self._get_context_for_template())
        fragment.add_content(loader.render_mako_template('/templates/html/student.html', context))
        fragment.add_css(loader.load_unicode('static/css/student.css'))
        fragment.add_javascript(loader.load_unicode('static/js/xblock_lti_consumer.js'))
        fragment.initialize_js('LtiConsumerXBlock')
        return fragment
Ejemplo n.º 10
0
    def student_view(self, context):
        """
        XBlock student view of this component.

        Arguments:
            context (dict): XBlock context

        Returns:
            xblock.fragment.Fragment: XBlock HTML fragment
        """
        fragment = Fragment()
        loader = ResourceLoader(__name__)
        context.update(self._get_context_for_template())
        fragment.add_content(
            loader.render_mako_template('/templates/player.html', context))
        '''
        Note: DO NOT USE the "latest" folder in production, but specify a version
                from https://aka.ms/ampchangelog. This allows us to run a test
                pass prior to ingesting later versions.
        '''
        fragment.add_css_url(
            '//amp.azure.net/libs/amp/1.8.1/skins/amp-default/azuremediaplayer.min.css'
        )
        fragment.add_javascript_url(
            '//amp.azure.net/libs/amp/1.8.1/azuremediaplayer.min.js')

        fragment.add_javascript(loader.load_unicode('static/js/player.js'))

        fragment.add_css(loader.load_unicode('public/css/player.css'))

        # NOTE: The Azure Media Player JS file includes the VTT JavaScript library, so we don't
        # actually need to include our local copy of public/js/vendor/vtt.js. In fact, if we do
        # the overlay subtitles stop working

        # @TODO: Make sure all fields are well structured/formatted, if it is not correct, then
        # print out an error msg in view rather than just silently failing

        fragment.initialize_js('AzureMediaServicesBlock')
        return fragment
Ejemplo n.º 11
0
    def student_view(self, context):
        """
        XBlock student view of this component.

        Arguments:
            context (dict): XBlock context

        Returns:
            xblock.fragment.Fragment: XBlock HTML fragment
        """
        fragment = Fragment()
        loader = ResourceLoader(__name__)
        context.update(self._get_context_for_template())
        fragment.add_content(loader.render_mako_template('/templates/player.html', context))

        '''
        Note: DO NOT USE the "latest" folder in production, but specify a version
                from https://aka.ms/ampchangelog . This allows us to run a test
                pass prior to ingesting later versions.
        '''
        fragment.add_javascript(loader.load_unicode('node_modules/videojs-vtt.js/lib/vttcue.js'))

        fragment.add_css_url('//amp.azure.net/libs/amp/1.8.1/skins/amp-default/azuremediaplayer.min.css')
        fragment.add_javascript_url('//amp.azure.net/libs/amp/1.8.1/azuremediaplayer.min.js')

        fragment.add_javascript(loader.load_unicode('static/js/player.js'))

        fragment.add_css(loader.load_unicode('public/css/player.css'))

        # NOTE: The Azure Media Player JS file includes the VTT JavaScript library, so we don't
        # actually need to include our local copy of public/js/vendor/vtt.js. In fact, if we do
        # the overlay subtitles stop working

        # @TODO: Make sure all fields are well structured/formatted, if it is not correct, then
        # print out an error msg in view rather than just silently failing

        fragment.initialize_js('AzureMediaServicesBlock')
        return fragment
Ejemplo n.º 12
0
 def test_render_mako_template(self):
     loader = ResourceLoader(__name__)
     s = loader.render_mako_template("data/simple_mako_template.txt",
                                     example_context)
     self.assertEqual(s, expected_filled_template)
Ejemplo n.º 13
0
 def test_render_mako_template(self):
     loader = ResourceLoader(__name__)
     s = loader.render_mako_template("data/simple_mako_template.txt", example_context)
     self.assertEquals(s, expected_filled_template)
Ejemplo n.º 14
0
def lti_embed(*,
              html_element_id,
              lti_launch_url,
              oauth_key,
              oauth_secret,
              resource_link_id,
              user_id,
              roles,
              context_id,
              context_title,
              context_label,
              result_sourcedid,
              person_sourcedid=None,
              person_contact_email_primary=None,
              outcome_service_url=None,
              launch_presentation_locale=None,
              **custom_parameters):
    """
    Returns an HTML template with JavaScript that will launch an LTI embed

    IMPORTANT NOTE: This method uses keyword only arguments as described in PEP 3102.
    Given the large number of arguments for this method, there is a  desire to
    guarantee that developers using this method know which arguments are being set
    to which values.
    See https://www.python.org/dev/peps/pep-3102/

    This method will use the LtiConsumer1p1 class to generate an HTML form and
    JavaScript that will automatically launch the LTI embedding, but it does not
    generate any response to encapsulate this content. The caller of this method
    must render the HTML on their own.

    Note: This method uses xblockutils.resources.ResourceLoader to load the HTML
    template used. The rationale for this is that ResourceLoader is agnostic
    to XBlock code and functionality. It is recommended that this remain in use
    until LTI1.3 support is merged, or a better means of loading the template is
    made available.

    Arguments:
        html_element_id (string):  Value to use as the HTML element id in the HTML form
        lti_launch_url (string):  The URL to send the LTI Launch request to
        oauth_key (string):  The OAuth consumer key
        oauth_secret (string):  The OAuth consumer secret
        resource_link_id (string):  Opaque identifier guaranteed to be unique
            for every placement of the link
        user_id (string):  Unique value identifying the user
        roles (string):  A comma separated list of role values
        context_id (string):  Opaque identifier used to uniquely identify the
            context that contains the link being launched
        context_title (string):  Plain text title of the context
        context_label (string):  Plain text label for the context
        result_sourcedid (string):  Indicates the LIS Result Identifier (if any)
            and uniquely identifies a row and column within the Tool Consumer gradebook
        person_sourcedid (string):  LIS identifier for the user account performing the launch
        person_contact_email_primary (string):  Primary contact email address of the user
        outcome_service_url (string):  URL pointing to the outcome service. This
            is required if the Tool Consumer is accepting outcomes for launches
            associated with the resource_link_id
        launch_presentation_locale (string):  Language, country and variant as
            represented using the IETF Best Practices for Tags for Identifying
            Languages (BCP-47)
        custom_parameters (dict): Contains any other keyword arguments not listed
            above. It will filter out all arguments provided that do not start with
            'custom_' and will submit the remaining arguments on the LTI Launch form

    Returns:
        unicode: HTML template with the form and JavaScript to automatically
            launch the LTI embedding
    """
    lti_consumer = LtiConsumer1p1(lti_launch_url, oauth_key, oauth_secret)

    # Set LTI parameters from kwargs
    lti_consumer.set_user_data(
        user_id,
        roles,
        result_sourcedid,
        person_sourcedid=person_sourcedid,
        person_contact_email_primary=person_contact_email_primary)
    lti_consumer.set_context_data(context_id, context_title, context_label)

    if outcome_service_url:
        lti_consumer.set_outcome_service_url(outcome_service_url)

    if launch_presentation_locale:
        lti_consumer.set_launch_presentation_locale(launch_presentation_locale)

    lti_consumer.set_custom_parameters({
        key: value
        for key, value in custom_parameters.items()
        if key.startswith('custom_')
    })

    lti_parameters = lti_consumer.generate_launch_request(resource_link_id)

    # Prepare form data
    context = {'launch_url': lti_launch_url, 'element_id': html_element_id}
    context.update({'lti_parameters': lti_parameters})

    # Render the form template and return the template
    loader = ResourceLoader(__name__)
    template = loader.render_mako_template(
        '../../templates/html/lti_launch.html', context)
    return template