From bbe602135a0acb446b891f967daa8d16af345f1c Mon Sep 17 00:00:00 2001 From: CJ Green <44074998+okaycj@users.noreply.github.com> Date: Sat, 5 Aug 2023 11:32:54 -0400 Subject: [PATCH] Update study type name field In addition to updating the study type field, I am removing the configuration field. Forms have replaced the need for this field. --- .../0091_remove_studytype_configuration.py | 55 +++++++++++++++++++ studies/models.py | 8 ++- 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 studies/migrations/0091_remove_studytype_configuration.py diff --git a/studies/migrations/0091_remove_studytype_configuration.py b/studies/migrations/0091_remove_studytype_configuration.py new file mode 100644 index 000000000..f26f0ed06 --- /dev/null +++ b/studies/migrations/0091_remove_studytype_configuration.py @@ -0,0 +1,55 @@ +# Generated by Django 3.2.11 on 2023-08-05 15:27 + +from django.db import migrations + +NAMES = { + "external": { + "old": "External", + "new": "External Study (Choose this if you are posting a study link rather using an experiment builder)", + }, + "efp": { + "old": "Ember Frame Player (default)", + "new": "Lookit/Ember Frame Player (Default experiment builder)", + }, +} + + +def study_type_names(apps, from_key, to_key): + study_type = apps.get_model("studies", "StudyType") + + # EFP name field + efp = study_type.objects.get(name=NAMES["efp"][from_key]) + efp.name = NAMES["efp"][to_key] + efp.save() + + # External name field + external = study_type.objects.get(name=NAMES["external"][from_key]) + external.name = NAMES["external"][to_key] + external.save() + + +def update_study_type_names(apps, schema_editor): + """Update the display names for study types.""" + study_type_names(apps, "old", "new") + + +def revert_study_type_names(apps, schema_editor): + """Update the display names for study types.""" + study_type_names(apps, "new", "old") + + +class Migration(migrations.Migration): + + dependencies = [ + ("studies", "0090_alter_study_preview_summary"), + ] + + operations = [ + migrations.RemoveField( + model_name="studytype", + name="configuration", + ), + migrations.RunPython( + update_study_type_names, reverse_code=revert_study_type_names + ), + ] diff --git a/studies/models.py b/studies/models.py index d32101726..eac32fbea 100644 --- a/studies/models.py +++ b/studies/models.py @@ -55,6 +55,9 @@ def default_configuration(): + """This function was used in the StudyType model. The field requiring this has + been removed. However, migrations still reference this function + """ return { # task module should have a build_experiment method decorated as a # celery task that takes a study uuid @@ -222,13 +225,12 @@ def notify_lab_of_approval(sender, instance, **kwargs): class StudyTypeEnum(Enum): - external = "External" - ember_frame_player = "Ember Frame Player (default)" + external = "External Study (Choose this if you are posting a study link rather using an experiment builder)" + ember_frame_player = "Lookit/Ember Frame Player (Default experiment builder)" class StudyType(models.Model): name = models.CharField(max_length=255, blank=False, null=False) - configuration = models.JSONField(default=default_configuration) def __str__(self): return self.name