Skip to content

Commit

Permalink
Fix LTI tool issues (#1405)
Browse files Browse the repository at this point in the history
Added a confirmation dialog for importing the contents
of a whole course via LTI in order to reduce the likelyhood
of accidentally importing a whole course's worth of content.

Also updated LTI module related views with correct classes
when rewriting exercise links with lti-exercise URLs, since
currently in production the isinstance calls don't match
the module exercises.
  • Loading branch information
murhum1 authored Oct 11, 2024
1 parent f558f93 commit 08ce8c3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 4 additions & 0 deletions locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5546,6 +5546,10 @@ msgstr "Use the whole course"
msgid "LTI_SELECT_SPECIFIC_CONTENT"
msgstr "Select specific content"

#: lti_tool/templates/lti_tool/course_list.html
msgid "LTI_CONFIRM_USE_WHOLE_COURSE"
msgstr "Are you sure you want to use the whole course?"

#: lti_tool/templates/lti_tool/exercise_list.html
#: lti_tool/templates/lti_tool/module_list.html
msgid "LTI_GO_BACK"
Expand Down
4 changes: 4 additions & 0 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5566,6 +5566,10 @@ msgstr "Valitse koko kurssi"
msgid "LTI_SELECT_SPECIFIC_CONTENT"
msgstr "Valitse tarkempaa sisältöä"

#: lti_tool/templates/lti_tool/course_list.html
msgid "LTI_CONFIRM_USE_WHOLE_COURSE"
msgstr "Haluatko varmasti valita koko kurssin?"

#: lti_tool/templates/lti_tool/exercise_list.html
#: lti_tool/templates/lti_tool/module_list.html
msgid "LTI_GO_BACK"
Expand Down
13 changes: 11 additions & 2 deletions lti_tool/templates/lti_tool/course_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ <h3 lang="{{ instance.language }}">
<form style="display: inline-block" method="POST" action="{{ instance_url }}">
{% csrf_token %}
<button
class="aplus-button--secondary aplus-button--xs"
type="submit"
class="use-whole-course-button aplus-button--secondary aplus-button--xs"
type="button"
>
{% translate "LTI_USE_WHOLE_COURSE" %}
</button>
Expand All @@ -52,4 +52,13 @@ <h3 lang="{{ instance.language }}">
{% endfor %}
</div>
</section>
<script>
$(document).ready(function() {
$(".use-whole-course-button").on("click", function() {
if (confirm("{% translate 'LTI_CONFIRM_USE_WHOLE_COURSE' %}")) {
$(this).closest("form").submit();
}
});
})
</script>
{% endblock %}
15 changes: 7 additions & 8 deletions lti_tool/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from course.views import InstanceView, ModuleView
from course.models import CourseInstance, Enrollment, CourseModule
from course.viewbase import CourseInstanceBaseView, CourseModuleBaseView
from exercise.cache.points import LearningObjectPoints
from exercise.cache.points import LearningObjectEntryBase
from exercise.viewbase import ExerciseBaseView
from exercise.models import LearningObject, BaseExercise
from exercise.views import ExerciseView, SubmissionView
Expand Down Expand Up @@ -172,12 +172,11 @@ class LtiModuleView(LtiSessionMixin, ModuleView):
def get(self, request, *args, **kwargs):
learningobjects = LearningObject.objects.filter(course_module=self.module)
learningobjects_dict = { obj.id: obj for obj in learningobjects }
# Can't use self.children for iteration, so this instead
flat_module = self.content.flat_module(self.module, level_markers=False)
exercises = [entry for entry in flat_module if isinstance(entry, LearningObjectPoints)]
for exercise in exercises:
learningobj = learningobjects_dict[exercise.id]
exercise.link = learningobj.get_url('lti-exercise')
self.children = list(self.children)
for exercise in self.children:
if isinstance(exercise, LearningObjectEntryBase):
learningobj = learningobjects_dict[exercise.id]
exercise.link = learningobj.get_url('lti-exercise')
return super().get(request, *args, **kwargs)


Expand Down Expand Up @@ -324,7 +323,7 @@ def get(self, request, *args, **kwargs):
self.learningobjects = LearningObject.objects.filter(course_module=self.module)
self.learningobjects_dict = { obj.id: obj for obj in self.learningobjects }
self.flat_module = list(self.content.flat_module(self.module))
exercises = [entry for entry in self.flat_module if isinstance(entry, LearningObjectPoints)]
exercises = [entry for entry in self.flat_module if isinstance(entry, LearningObjectEntryBase)]
for exercise in exercises:
learningobj = self.learningobjects_dict[exercise.id]
exercise.link = learningobj.get_url('lti-select-exercise')
Expand Down

0 comments on commit 08ce8c3

Please sign in to comment.