Amsterdam-Music-Lab / MUSCLE

An application to easily set up and run online listening experiments for music research.
https://www.amsterdammusiclab.nl/
MIT License
4 stars 1 forks source link

Added: Add translated_content model and update Experiment model #1208

Closed drikusroor closed 1 month ago

drikusroor commented 2 months ago

This PR adds the ExperimentTranslatedContent model to the application, along with its related functionality. It has the following properties:

Model

The PR also adds some helper methods to the Experiment model, get_fallback_content and get_translated_content. These are used to get the appropriate content for the given context.

https://github.com/Amsterdam-Music-Lab/MUSCLE/blob/5d90e4b27b777530ad5ad19d6a0fe166fd25550e/backend/experiment/models.py#L68-L87

Serialisation & active language handling

The languages of the configured ExperimentTranslatedContents for an Experiment determine the possible languages in which an experiment can be used. These languages will also determine the languages used at the SocialMediaConfig, ThemeConfig, and Block level. Right now, what happens is that the user has a preferred language that is used to get the appropriate content and fall back to the experiment's fallback language if it is not available. Django has the get_language helper function to determine the user's preferred language. This language is used to find the appropriate ExperimentTranslatedContent. If it cannot find it, it will take the experiment's translated content with the lowest index number. If that doesn't exist either, it will throw an error as an Experiment needs a content in order to work. (We might want to require at least one translated content per experiment during creation and updating.)

The language of the ExperimentTranslatedContent (preferred or fallback) will be used as the active language for the whole experiment, its related entities, and the non-experiment related content using Django activate(language) function (which was used earlier at the Block level depending on the configured language there.

https://github.com/Amsterdam-Music-Lab/MUSCLE/blob/066b9381fd64d57a502b5516a93212f207cd9916/backend/experiment/views.py#L128-L136

Consent

The retrieval of the consent form works slightly different. If a consent form cannot be found in the preferred language, but does exist at the fallback level, the consent form from the fallback language will be used. This gives the user flexibility in configuring consent form: Configure consent forms in all languages, configure consent forms in only one or a limited selection of the experiment languages, or configure no consent forms at all.

Things to do after merging this PR

The migrations copy the Experiment's content to a newly created ExperimentLanguageContent, with the language set to English. This means that we have to go over all experiments after the migration and set the language to Dutch or Chinese if that's the Experiment's original language.

Related to #1204

sentry-io[bot] commented 1 month ago

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

Did you find this useful? React with a 👍 or 👎