Skip to content

Commit

Permalink
Update study type name field
Browse files Browse the repository at this point in the history
In addition to updating the study type field, I am removing the
configuration field.  Forms have replaced the need for this field.
  • Loading branch information
okaycj committed Aug 5, 2023
1 parent 96431f3 commit bbe6021
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
55 changes: 55 additions & 0 deletions studies/migrations/0091_remove_studytype_configuration.py
Original file line number Diff line number Diff line change
@@ -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
),
]
8 changes: 5 additions & 3 deletions studies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bbe6021

Please sign in to comment.