numbas / numbas-lti-provider

An LTI tool provider to run Numbas exams
https://docs.numbas.org.uk/lti/en/latest/
Other
11 stars 12 forks source link

Loading standalone scripts doesn't work in the auto re-mark page #229

Open christianp opened 2 years ago

christianp commented 2 years ago

The URL seems to be relative to the re-mark page, not the exam

georgestagg commented 2 years ago

Something like this seems to work, but I don't know if you'd consider it the right approach:

--- a/numbas_lti/views/resource.py
+++ b/numbas_lti/views/resource.py
@@ -582,6 +582,7 @@ class RemarkIframeView(MustHaveExamMixin,ResourceManagementViewMixin,MustBeInstr
     def get_context_data(self, *args, **kwargs):
         context = super().get_context_data(*args,**kwargs)
         resource = self.object
+        context['extensions_url'] = resource.exam.extracted_url + '/extensions/'
         context['scripts_url'] = resource.exam.extracted_url +'/scripts.js'
         return context
--- a/numbas_lti/templates/numbas_lti/management/resource_remark_iframe.html
+++ b/numbas_lti/templates/numbas_lti/management/resource_remark_iframe.html
@@ -7,6 +7,9 @@
     <head>
         {% get_current_language as LANGUAGE_CODE %}
         <script src="{% statici18n LANGUAGE_CODE %}"></script>
+        <script>
+            var numbas_extensions_url = "{{extensions_url}}";
+        </script>
         <script src="{{scripts_url}}"></script>
         <script src="{% static 'resource_remark_iframe.js' %}"></script>
     </head>
--- a/numbas_lti/static/resource_remark_iframe.js
+++ b/numbas_lti/static/resource_remark_iframe.js
@@ -5,6 +5,9 @@ function die(e) {

 const numbas_ready = new Promise((resolve,reject) => {
     try {
+        Numbas.getStandaloneFileURL = function(extension, path) {
+            return numbas_extensions_url+extension+'/standalone_scripts/'+path;
+        }
         Numbas.queueScript('web-remarking',['start-exam'],function() {
             try {
                 for(var x in Numbas.extensions) {