mirror of
https://github.com/ae-utbm/sith.git
synced 2026-11-20 16:09:54 +00:00
73 lines
2.7 KiB
Python
73 lines
2.7 KiB
Python
# Generated by Django 5.2.18 on 2026-11-14 11:44
|
|
from typing import TYPE_CHECKING
|
|
|
|
from django.db import migrations, models
|
|
from django.db.models import F
|
|
from django.db.models.expressions import Case, Value, When
|
|
|
|
if TYPE_CHECKING:
|
|
from django.db.migrations.state import StateApps
|
|
|
|
|
|
def copy_name(apps: StateApps, schema_editor):
|
|
"""Automatically populate French names and the most common English ones"""
|
|
ClubRole = apps.get_model("club", "ClubRole")
|
|
ClubRole.objects.update(
|
|
name_fr=F("name"),
|
|
name_en=Case(
|
|
When(name="Président⸱e", then=Value("President")),
|
|
When(name="Vice-Président⸱e", then=Value("Vice-president")),
|
|
When(name="Trésorier⸱e", then=Value("Treasurer")),
|
|
When(name="Responsable communication", then=Value("Communication manager")),
|
|
When(name="Secrétaire", then=Value("Secretary")),
|
|
When(name="Responsable info", then=Value("IT manager")),
|
|
When(name="Membre du bureau", then=Value("Board member")),
|
|
When(name="Membre actif⸱ve", then=Value("Active member")),
|
|
When(name="Curieux⸱euse", then=Value("Curious")),
|
|
),
|
|
)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [("club", "0019_remove_mailingsubscription_mailing_and_more")]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name="clubrole",
|
|
name="name_en",
|
|
field=models.CharField(max_length=50, null=True, verbose_name="name"),
|
|
),
|
|
migrations.AddField(
|
|
model_name="clubrole",
|
|
name="name_fr",
|
|
field=models.CharField(max_length=50, null=True, verbose_name="name"),
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name="clubrole",
|
|
constraint=models.UniqueConstraint(
|
|
fields=("club", "name"),
|
|
name="clubrole_club_name_unique",
|
|
violation_error_message="There is already a role with that name",
|
|
),
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name="clubrole",
|
|
constraint=models.UniqueConstraint(
|
|
fields=("club", "name_fr"),
|
|
name="clubrole_club_name_unique-fr",
|
|
violation_error_message="There is already a role with that name",
|
|
),
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name="clubrole",
|
|
constraint=models.UniqueConstraint(
|
|
fields=("club", "name_en"),
|
|
name="clubrole_club_name_unique-en",
|
|
violation_error_message="There is already a role with that name",
|
|
),
|
|
),
|
|
migrations.RunPython(
|
|
copy_name, reverse_code=migrations.RunPython.noop, elidable=True
|
|
),
|
|
]
|