-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8295c29
commit 7233f28
Showing
6 changed files
with
134 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
core/migrations/0069_alter_user_options_user_staff_bio_and_more.py
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
core/migrations/0069_staffmember_alter_user_options_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Generated by Django 5.0 on 2024-01-03 05:44 | ||
|
||
import core.utils.multiselectfield | ||
import django.db.models.deletion | ||
import django.db.models.functions.text | ||
from django.conf import settings | ||
from django.db import migrations, models, IntegrityError | ||
|
||
|
||
def populate_bios(apps, schema_editor): | ||
StaffMember = apps.get_model("core", "StaffMember") | ||
User = apps.get_model("core", "User") | ||
|
||
for position, user_ids in settings.METROPOLIS_STAFFS.items(): | ||
for user_id in user_ids: | ||
try: | ||
user = User.objects.get(pk=user_id) | ||
bio = settings.METROPOLIS_STAFF_BIO.get(user_id, "") | ||
staff_member, created = StaffMember.objects.get_or_create(user=user, bio=bio) | ||
staff_member.position += [position] | ||
staff_member.save() | ||
except User.DoesNotExist: | ||
print(f"User {user_id} does not exist") | ||
except IntegrityError: | ||
print(f"StaffMember for user {user_id} already exists") | ||
|
||
def reversed_pop(apps, schema_editor): | ||
raise RuntimeError("Cannot reverse this migration.") | ||
# just uncomment the above line if you want to reverse this migration, but you will lose all staff bios | ||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("auth", "0012_alter_user_first_name_max_length"), | ||
( | ||
"core", | ||
"0058_fix_blogpost_featured_image_description_squashed_0068_remove_user_expo_notif_token_delete_recurrencerule", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="StaffMember", | ||
fields=[ | ||
( | ||
"user", | ||
models.OneToOneField( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
primary_key=True, | ||
related_name="staff", | ||
serialize=False, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
("bio", models.TextField()), | ||
( | ||
"position", | ||
core.utils.multiselectfield.MultiSelectField( | ||
max_length=200, | ||
verbose_name=( | ||
("PM", "Project Manager"), | ||
("frontend", "Frontend Developer"), | ||
("backend", "Backend Developer"), | ||
("app", "App Developer"), | ||
("graphics", "Graphic Designer"), | ||
("content", "Content Creator"), | ||
("doodle", "Doodle Developer"), | ||
), | ||
), | ||
), | ||
( | ||
"years", | ||
core.utils.multiselectfield.MultiSelectField( | ||
max_length=200, | ||
verbose_name=[ | ||
"2021-22", | ||
"2022-23", | ||
"2023-24", | ||
"2024-25", | ||
"2025-26", | ||
], | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Staff Member", | ||
"verbose_name_plural": "Staff Members", | ||
}, | ||
), | ||
migrations.AlterModelOptions( | ||
name="user", | ||
options={}, | ||
), | ||
migrations.AddConstraint( | ||
model_name="user", | ||
constraint=models.UniqueConstraint( | ||
django.db.models.functions.text.Lower("username"), | ||
name="username-lower-check", | ||
), | ||
), | ||
migrations.RunPython(populate_bios, reverse_code=reversed_pop), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters