112 lines
3.2 KiB
Python
112 lines
3.2 KiB
Python
import django.db.models.deletion
|
|
from django.db import migrations, models
|
|
|
|
TEST_COURSE_ID = -1
|
|
|
|
UK_COURSE_IDS = [
|
|
-3, # uk-de
|
|
-6, # uk-training-de
|
|
-5, # uk-fr
|
|
-7, # uk-training-fr
|
|
-8, # uk-it
|
|
-9, # uk-training-it
|
|
]
|
|
|
|
|
|
VV_COURSE_IDS = [
|
|
-4, # vv-de
|
|
-10, # vv-fr
|
|
-11, # vv-it
|
|
-12, # vv-prüfung
|
|
]
|
|
|
|
|
|
def forward_migration(apps, schema_editor):
|
|
Course = apps.get_model("course", "Course")
|
|
CourseConfiguration = apps.get_model("course", "CourseConfiguration")
|
|
|
|
for course in Course.objects.all():
|
|
config, created = CourseConfiguration.objects.get_or_create(
|
|
course=course,
|
|
)
|
|
|
|
if created:
|
|
# moved -> use existing value from course
|
|
config.enable_circle_documents = course.enable_circle_documents
|
|
|
|
# by default everything is enabled
|
|
# -> disable unnecessary features
|
|
if course.id in UK_COURSE_IDS:
|
|
config.enable_learning_mentor = False
|
|
elif course.id in VV_COURSE_IDS:
|
|
config.enable_competence_certificates = False
|
|
|
|
config.save()
|
|
|
|
|
|
def backward_migration(apps, schema_editor):
|
|
CourseConfiguration = apps.get_model("course", "CourseConfiguration")
|
|
|
|
for config in CourseConfiguration.objects.all():
|
|
course = config.course
|
|
course.enable_circle_documents = config.enable_circle_documents
|
|
course.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("course", "0006_auto_20231221_1411"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name="CourseConfiguration",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.BigAutoField(
|
|
auto_created=True,
|
|
primary_key=True,
|
|
serialize=False,
|
|
verbose_name="ID",
|
|
),
|
|
),
|
|
(
|
|
"enable_circle_documents",
|
|
models.BooleanField(
|
|
default=True, verbose_name="Dokumente im Circle ein/aus"
|
|
),
|
|
),
|
|
(
|
|
"enable_learning_mentor",
|
|
models.BooleanField(
|
|
default=True, verbose_name="Lernmentor-Funktion ein/aus"
|
|
),
|
|
),
|
|
(
|
|
"enable_competence_certificates",
|
|
models.BooleanField(
|
|
default=True, verbose_name="Kompetenzweise ein/aus"
|
|
),
|
|
),
|
|
(
|
|
"course",
|
|
models.OneToOneField(
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
related_name="configuration",
|
|
to="course.course",
|
|
),
|
|
),
|
|
],
|
|
),
|
|
migrations.RunPython(forward_migration, backward_migration),
|
|
migrations.RemoveField(
|
|
model_name="course",
|
|
name="circle_contact_type",
|
|
),
|
|
migrations.RemoveField(
|
|
model_name="course",
|
|
name="enable_circle_documents",
|
|
),
|
|
]
|