Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dependencies = [
"openedx-calc",
"path",
"pyparsing",
"pytz",
"random2",
"requests",
"shapely",
Expand Down
34 changes: 31 additions & 3 deletions src/xblock_lti/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
from unittest import mock
from urllib import parse
from xml.sax.saxutils import escape
from zoneinfo import ZoneInfo

import markupsafe
import nh3
Expand All @@ -71,7 +72,6 @@
from lxml import etree
from oauthlib.oauth1.rfc5849 import signature
from opaque_keys.edx.keys import CourseKey
from pytz import UTC
from web_fragments.fragment import Fragment
from webob import Response
from xblock.core import List, Scope, String, XBlock
Expand All @@ -94,7 +94,7 @@

DOCS_ANCHOR_TAG_OPEN = (
"<a rel='noopener' target='_blank' "
"href='https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/lti_component.html'>"
"href='https://docs.openedx.org/en/latest/educators/navigation/components_activities.html#lti-component'>"
)
BREAK_TAG = "<br />"

Expand Down Expand Up @@ -389,6 +389,7 @@ class LTIBlock(

# Indicates that this XBlock has been extracted from edx-platform.
is_extracted = True
i18n_js_namespace = "XBlockLTII18N"

def max_score(self):
return self.weight if self.has_score else None
Expand Down Expand Up @@ -499,6 +500,18 @@ def get_context(self):
# This lets all plaintext through.
sanitized_comment = nh3.clean(self.score_comment)

# The score text next to the title, translated with the block's catalog as in the built-in block.
gettext = self.runtime.service(self, "i18n").ugettext
if self.module_score is not None:
# Translators: "points" is the student's achieved score on this LTI unit, and "total_points" is the
# maximum number of points achievable.
score_text = gettext("{points} / {total_points} points").format(
points=self.module_score, total_points=self.weight
)
else:
# Translators: "total_points" is the maximum number of points achievable on this LTI unit
score_text = gettext("{total_points} points possible").format(total_points=self.weight)

return {
"input_fields": self.get_input_fields(),
# These parameters do not participate in OAuth signing.
Expand All @@ -512,6 +525,7 @@ def get_context(self):
"has_score": self.has_score,
"weight": self.weight,
"module_score": self.module_score,
"score_text": score_text,
"comment": sanitized_comment,
"description": self.description,
"ask_to_send_username": self.ask_to_send_username,
Expand All @@ -520,6 +534,19 @@ def get_context(self):
"accept_grades_past_due": self.accept_grades_past_due,
}

def _add_i18n_js_catalog(self, fragment):
"""
Add this block's JavaScript translation catalog to the fragment, if the runtime provides one.

The catalog defines ``window.XBlockLTII18N`` (see ``i18n_js_namespace``).
Add it before the block's own JS.
"""
i18n_service = self.runtime.service(self, "i18n")
url_getter = getattr(i18n_service, "get_javascript_i18n_catalog_url", None)
url = url_getter(self) if url_getter else None
if url:
fragment.add_javascript_url(url)

def student_view(self, _context=None):
"""
Create primary view of the LTIBlock, shown to students when viewing courses.
Expand All @@ -532,6 +559,7 @@ def student_view(self, _context=None):
)

frag.add_css(resource_loader.load_unicode("static/css/lti.css"))
self._add_i18n_js_catalog(frag)
frag.add_javascript(resource_loader.load_unicode("static/js/src/lti.js"))
frag.initialize_js("LTIBlock")
return frag
Expand Down Expand Up @@ -1006,7 +1034,7 @@ def is_past_due(self):
close_date = due_date + self.graceperiod
else:
close_date = due_date
return close_date is not None and datetime.datetime.now(UTC) > close_date
return close_date is not None and datetime.datetime.now(ZoneInfo("UTC")) > close_date

@classmethod
def definition_from_xml(cls, xml_object, system):
Expand Down
24 changes: 13 additions & 11 deletions src/xblock_lti/static/css/lti.css
Original file line number Diff line number Diff line change
@@ -1,57 +1,59 @@
/* CSS for LTIBlock */
/* CSS for LTIBlock. Every rule is scoped to the block's root element (.lti-wrapper in
templates/lti.html) so it can't restyle other blocks on the page, as the built-in block's
.xmodule_display.xmodule_LTIBlock scope did. */

@import url("https://fonts.googleapis.com/css?family=Open+Sans:300,400,400i,600,700");

h2.problem-header {
.lti-wrapper h2.problem-header {
display: inline-block;
}

div.problem-progress {
.lti-wrapper div.problem-progress {
display: inline-block;
padding-left: 5px;
color: #666;
font-weight: 100;
font-size: 1em;
}

div.lti {
.lti-wrapper div.lti {
margin: 0 auto;
}

div.lti .wrapper-lti-link {
.lti-wrapper div.lti .wrapper-lti-link {
font-size: 14px;
background-color: #f6f6f6;
padding: 20px;
}

div.lti .wrapper-lti-link .lti-link {
.lti-wrapper div.lti .wrapper-lti-link .lti-link {
margin-bottom: 0;
text-align: right;
}

div.lti .wrapper-lti-link .lti-link .link_lti_new_window {
.lti-wrapper div.lti .wrapper-lti-link .lti-link .link_lti_new_window {
font-size: 13px;
line-height: 20.72px;
}

div.lti form.ltiLaunchForm {
.lti-wrapper div.lti form.ltiLaunchForm {
display: none;
}

div.lti iframe.ltiLaunchFrame {
.lti-wrapper div.lti iframe.ltiLaunchFrame {
width: 100%;
height: 800px;
display: block;
border: 0px;
}

div.lti h4.problem-feedback-label {
.lti-wrapper div.lti h4.problem-feedback-label {
font-weight: 100;
font-size: 1em;
font-family: "Source Sans", "Open Sans", Verdana, Geneva, sans-serif, sans-serif;
}

div.lti div.problem-feedback {
.lti-wrapper div.lti div.problem-feedback {
margin-top: 5px;
margin-bottom: 5px;
}
15 changes: 12 additions & 3 deletions src/xblock_lti/static/js/src/lti.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
function LTIBlock(runtime, element) {
'use strict';

/*
Use this block's translation catalog (window.XBlockLTII18N, loaded by the
runtime before this file) when it is available, else the page's global gettext.
*/
function gettext(msgid) {
var catalog = window.XBlockLTII18N || window;
return catalog.gettext ? catalog.gettext(msgid) : msgid;
}

const $lti = $(element).find('.lti');
const askToSendUsername = $lti.data('ask-to-send-username') === 'True';
const askToSendEmail = $lti.data('ask-to-send-email') === 'True';
Expand All @@ -11,11 +20,11 @@ function LTIBlock(runtime, element) {
// accept or reject sending their information to a third party
$(element).on('click', '.link_lti_new_window', function() {
if (askToSendUsername && askToSendEmail) {
return confirm('Click OK to have your username and e-mail address sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.');
return confirm(gettext('Click OK to have your username and e-mail address sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.'));
} else if (askToSendUsername) {
return confirm('Click OK to have your username sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.');
return confirm(gettext('Click OK to have your username sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.'));
} else if (askToSendEmail) {
return confirm('Click OK to have your e-mail address sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.');
return confirm(gettext('Click OK to have your e-mail address sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.'));
} else {
return true;
}
Expand Down
20 changes: 5 additions & 15 deletions src/xblock_lti/templates/lti.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@ <h3 class="hd hd-3 problem-header">
</h3>

{% if has_score and weight %}
<div class="problem-progress">
{% if module_score is not None %}
{# Translators: "points" is the student's achieved score on this LTI unit, and "total_points" is the maximum number of points achievable. #}
{% trans "points" as points_trans %}
{% trans "{points} / {total_points} points" as score_trans %}
({{ module_score }} / {{ weight }} {{ points_trans }})
{% else %}
{# Translators: "total_points" is the maximum number of points achievable on this LTI unit #}
{% trans "total_points" as total_points_trans %}
({{ weight }} {{ total_points_trans }} possible)
{% endif %}
</div>
<div class="problem-progress">({{ score_text }})</div>
{% endif %}

<div
Expand All @@ -37,7 +26,8 @@ <h3 class="hd hd-3 problem-header">
{% endif %}
<p class="lti-link external">
<a target="_blank" class="link_lti_new_window" rel="noopener" href="{{ form_url }}">
{{ button_text|default:_('View resource in a new window') }}
{% trans 'View resource in a new window' as default_button_text %}
{{ button_text|default:default_button_text }}
<span class="icon fa fa-external-link" aria-hidden="true"></span>
</a>
</p>
Expand All @@ -57,12 +47,12 @@ <h3 class="hd hd-3 problem-header">
{% endif %}
{% elif not hide_launch %}
<h4 class="hd hd-4 error_message">
{{ _('Please provide launch_url. Click "Edit", and fill in the required fields.') }}
{% trans 'Please provide launch_url. Click "Edit", and fill in the required fields.' %}
</h4>
{% endif %}

{% if has_score and comment %}
<h4 class="hd hd-4 problem-feedback-label">${_("Feedback on your work from the grader:")}</h4>
<h4 class="hd hd-4 problem-feedback-label">{% trans "Feedback on your work from the grader:" %}</h4>
<div class="problem-feedback">
{# sanitized with nh3 in view #}
{{ comment|safe }}
Expand Down
4 changes: 2 additions & 2 deletions src/xblock_lti/tests/test_lti20_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import datetime
import textwrap
from unittest.mock import Mock
from zoneinfo import ZoneInfo

from django.conf import settings
from django.test import TestCase, override_settings
from pytz import UTC
from xblock.field_data import DictFieldData

from xblock_lti.block import LTIBlock
Expand Down Expand Up @@ -422,7 +422,7 @@ def test_lti20_request_handler_grade_past_due(self):
Test that we get a 404 when accept_grades_past_due is False and it is past due
"""
self.setup_system_xblock_mocks_for_lti20_request_test()
self.xblock.due = datetime.datetime.now(UTC)
self.xblock.due = datetime.datetime.now(ZoneInfo("UTC"))
self.xblock.accept_grades_past_due = False
mock_request = self.get_signed_lti20_mock_request(self.GOOD_JSON_PUT)
response = self.xblock.lti_2_0_result_rest_handler(mock_request, "user/abcd")
Expand Down
Loading
Loading