numbas / numbas-extension-programming

An extension for Numbas which provides a code editor and the ability to evaluate code written in Python and R.
Apache License 2.0
3 stars 1 forks source link

Pre-loading files fails when used in multiple exam questions #34

Closed chrismgraham closed 2 months ago

chrismgraham commented 3 months ago

The file in the first question loads OK, but files in subsequent questions aren't loaded: see e.g. https://numbas.mathcentre.ac.uk/exam/35150/two-resource-questions/embed/?token=40d7fc57-e41f-41ae-a09f-3bf858a6bd6b

christianp commented 2 months ago

Fixed by bac7d72acb36b8bf180ee9bd3b41e1cd5b3076bc.

There's now a context_id parameter for the preload function, which you should set to the current question's number. This ensures that you can only access the current question's files from code in that question. If the context_id isn't given, the files are put in the global context and are available to every question in the exam.

So add context_id: question.number to your preload options.