46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from django.db import migrations, models
|
|
|
|
|
|
def migrate_legacy_statuses(apps, schema_editor):
|
|
User = apps.get_model("accounts", "User")
|
|
for user in User.objects.all():
|
|
if user.status == "superadmin":
|
|
new_status = "director_admin"
|
|
flags = {"is_active": True, "is_staff": True, "is_superuser": True}
|
|
elif user.status == "active":
|
|
new_status = "gm"
|
|
flags = {"is_active": True, "is_staff": False, "is_superuser": False}
|
|
elif user.status == "inactive":
|
|
new_status = "inactive"
|
|
flags = {"is_active": False, "is_staff": False, "is_superuser": False}
|
|
else:
|
|
continue
|
|
User.objects.filter(pk=user.pk).update(status=new_status, **flags)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("accounts", "0004_sync_status_flags"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AlterField(
|
|
model_name="user",
|
|
name="status",
|
|
field=models.CharField(
|
|
choices=[
|
|
("inactive", "Inactive"),
|
|
("gm", "GM"),
|
|
("gm_admin", "GM Admin"),
|
|
("buh", "BUH"),
|
|
("bu_admin", "BU Admin"),
|
|
("director", "Director"),
|
|
("director_admin", "Director Admin"),
|
|
],
|
|
default="gm",
|
|
max_length=30,
|
|
),
|
|
),
|
|
migrations.RunPython(migrate_legacy_statuses, migrations.RunPython.noop),
|
|
]
|