Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
janno42 committed Dec 21, 2021
2 parents 757cade + 1427e47 commit dac9376
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
33 changes: 28 additions & 5 deletions evap/evaluation/migrations/0123_evaluation_state_fsm_int.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import migrations
import django_fsm


# as defined in the Evaluation model
Expand All @@ -24,28 +23,52 @@ class State:
"reviewed": State.REVIEWED,
"published": State.PUBLISHED,
}
REV_CONVERSION = {val: key for key, val in CONVERSION.items()}


def str_to_int(apps, _schema_editor):
def model_str_to_int(apps, _schema_editor):
Evaluation = apps.get_model("evaluation", "Evaluation")
for string_type, int_type in CONVERSION.items():
Evaluation.objects.filter(state=string_type).update(int_state=int_type)


def int_to_str(apps, _schema_editor):
def model_int_to_str(apps, _schema_editor):
Evaluation = apps.get_model("evaluation", "Evaluation")
for string_type, int_type in CONVERSION.items():
Evaluation.objects.filter(int_state=int_type).update(state=string_type)


def logentries_str_to_int(apps, _schema_editor):
LogEntry = apps.get_model("evaluation", "LogEntry")
for entry in LogEntry.objects.filter(content_type__app_label="evaluation", content_type__model="evaluation"):
if "state" in entry.data:
for key in entry.data["state"]:
entry.data["state"][key] = [
CONVERSION[val] if val in CONVERSION else val for val in entry.data["state"][key]
]
entry.save()


def logentries_int_to_str(apps, _schema_editor):
LogEntry = apps.get_model("evaluation", "LogEntry")
for entry in LogEntry.objects.filter(content_type__app_label="evaluation", content_type__model="evaluation"):
if "state" in entry.data:
for key in entry.data["state"]:
entry.data["state"][key] = [
REV_CONVERSION[val] if val in REV_CONVERSION else val for val in entry.data["state"][key]
]
entry.save()


class Migration(migrations.Migration):

dependencies = [
('evaluation', '0122_prepare_evaluation_state_fsm_int'),
("evaluation", "0122_prepare_evaluation_state_fsm_int"),
]

operations = [
migrations.RunPython(str_to_int, int_to_str),
migrations.RunPython(model_str_to_int, model_int_to_str),
migrations.RunPython(logentries_str_to_int, logentries_int_to_str),
migrations.RemoveField(
model_name="evaluation",
name="state",
Expand Down
19 changes: 19 additions & 0 deletions evap/evaluation/migrations/0127_fix_logentry_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import importlib
from django.db import migrations

original_migration_module = importlib.import_module("evap.evaluation.migrations.0123_evaluation_state_fsm_int")


class Migration(migrations.Migration):
"""
Initially, we forgot to migrate logentries in 0123, so this migration cleans this up.
Note that 0123 is now modified to also take care of the logentries in the first place.
"""

dependencies = [
("evaluation", "0126_add_textanswer_review_email_template"),
]

operations = [
migrations.RunPython(original_migration_module.logentries_str_to_int, migrations.RunPython.noop),
]

0 comments on commit dac9376

Please sign in to comment.