From 3e3f4c1b196908d22f83033ff6a30a30fec68752 Mon Sep 17 00:00:00 2001 From: Gunvor4 Date: Thu, 7 Mar 2024 18:49:30 +0100 Subject: [PATCH] Squashed migrations --- ...toricalmember_discord_username_and_more.py | 415 ++++++++++++++++++ 1 file changed, 415 insertions(+) create mode 100644 src/internal/migrations/0001_squashed_0027_alter_historicalmember_discord_username_and_more.py diff --git a/src/internal/migrations/0001_squashed_0027_alter_historicalmember_discord_username_and_more.py b/src/internal/migrations/0001_squashed_0027_alter_historicalmember_discord_username_and_more.py new file mode 100644 index 00000000..411b27eb --- /dev/null +++ b/src/internal/migrations/0001_squashed_0027_alter_historicalmember_discord_username_and_more.py @@ -0,0 +1,415 @@ +# Generated by Django 4.2.9 on 2024-03-07 17:31 + +import ckeditor_uploader.fields +import datetime +from django.conf import settings +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion +import internal.modelfields +import internal.validators +import json +import phonenumber_field.modelfields +import re +import simple_history.models +import web.modelfields +from web.multilingual.data_structures import MultiLingualTextStructure +import web.multilingual.modelfields + + +def update_user_card_from_member(apps, schema_editor): + """ + Set user card number from member card number + """ + Member = apps.get_model('internal', 'Member') + db_alias = schema_editor.connection.alias + + for member in Member.objects.using(db_alias).all(): + if member.card_number and member.user: + member.user.card_number = member.card_number + member.user.save(using=db_alias) + + +def reverse_update_user_card_from_member(apps, schema_editor): + """ + Reverse setting of card number on user + """ + Member = apps.get_model('internal', 'Member') + db_alias = schema_editor.connection.alias + + for member in Member.objects.using(db_alias).all(): + if member.user and member.user.card_number: + member.card_number = member.user.card_number + member.save(using=db_alias) + + +def get_default_language_text(json: str): + text_structure = MultiLingualTextStructure(json, use_default_for_empty=True) + return text_structure[settings.LANGUAGE_CODE] + + +def convert_multi_lingual_text_structure_to_plain_text(apps, schema_editor): + Secret = apps.get_model('internal', 'Secret') + for secret in Secret.objects.all(): + secret.title = get_default_language_text(secret.title) + secret.content = get_default_language_text(secret.content) + secret.save() + + +def get_json_with_default_language(plain_text: str): + text_structure = MultiLingualTextStructure("", languages={settings.LANGUAGE_CODE}, use_default_for_empty=True) + text_structure[settings.LANGUAGE_CODE] = plain_text + return json.dumps(text_structure.languages, ensure_ascii=False) + + +def convert_plain_text_to_multi_lingual_text_structure(apps, schema_editor): + Secret = apps.get_model('internal', 'Secret') + for secret in Secret.objects.all(): + secret.title = get_json_with_default_language(secret.title) + secret.content = get_json_with_default_language(secret.content) + secret.save() + + +class Migration(migrations.Migration): + + replaces = [('internal', '0001_initial'), ('internal', '0002_verbose_names_and_allow_blank'), ('internal', '0003_member_property_to_system_access'), ('internal', '0004_member_phone_number_field'), ('internal', '0005_remove_member_card_number'), ('internal', '0006_secret'), ('internal', '0007_remove_member_fields_max_length_and_null'), ('internal', '0008_systemaccess_unique_name_per_member'), ('internal', '0009_alter_id_fields_to_use_bigautofield'), ('internal', '0010_add_related_names'), ('internal', '0011_secret_priority'), ('internal', '0012_member_and_systemaccess_last_modified'), ('internal', '0013_rename_date_quit'), ('internal', '0014_rename_email_to_contact_email'), ('internal', '0015_member_gmail_and_MAKE_email_and_ntnu_starting_semester_and_github_and_discord_and_minecraft_username'), ('internal', '0016_can_change_rich_text_source_permission'), ('internal', '0017_historicalsecret'), ('internal', '0018_quote'), ('internal', '0019_quote_date'), ('internal', '0020_history_date_db_index'), ('internal', '0021_alter_historicalsecret_content_and_more'), ('internal', '0022_member_user_set_null_on_delete'), ('internal', '0023_rename_gmail_member_google_email'), ('internal', '0024_historicalmember_and_historicalmember_committees'), ('internal', '0025_secret_extra_view_permissions_and_historicalsecret_extra_view_permissions'), ('internal', '0026_add_secret_permissions'), ('internal', '0027_alter_historicalmember_discord_username_and_more')] + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('groups', '0012_history_date_db_index'), + ('groups', '0004_auto_20181009_1356'), + ('auth', '0012_alter_user_first_name_max_length'), + ('users', '0003_user_card_number'), + ] + + operations = [ + migrations.CreateModel( + name='Member', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('role', models.CharField(blank=True, max_length=64, verbose_name='role')), + ('email', models.EmailField(blank=True, max_length=254, null=True, verbose_name='contact email')), + ('phone_number', phonenumber_field.modelfields.PhoneNumberField(blank=True, default='', max_length=32, region=None, verbose_name='phone number')), + ('study_program', models.CharField(blank=True, default='', max_length=32, verbose_name='study program')), + ('card_number', models.CharField(blank=True, default='', max_length=32, verbose_name='card number (EM)')), + ('date_joined', models.DateField(default=datetime.datetime.now, verbose_name='date joined')), + ('date_quit', models.DateField(blank=True, null=True, verbose_name='date quit')), + ('reason_quit', models.TextField(blank=True, default='', max_length=256, verbose_name='reason quit')), + ('comment', models.TextField(blank=True, default='', max_length=256, verbose_name='comment')), + ('active', models.BooleanField(default=True, verbose_name='is active')), + ('guidance_exemption', models.BooleanField(default=False, verbose_name='guidance exemption')), + ('quit', models.BooleanField(default=False, verbose_name='has quit')), + ('retired', models.BooleanField(default=False, verbose_name='retired')), + ('committees', models.ManyToManyField(blank=True, to='groups.committee', verbose_name='committees')), + ('user', models.OneToOneField(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL, verbose_name='user')), + ('honorary', models.BooleanField(default=False, verbose_name='honorary')), + ], + options={ + 'permissions': (('is_internal', 'Is a member of MAKE NTNU'), ('can_edit_group_membership', 'Can edit the groups a member is part of, including (de)activation')), + }, + ), + migrations.CreateModel( + name='SystemAccess', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(choices=[('drive', 'Drive'), ('slack', 'Slack'), ('calendar', 'Calendar'), ('trello', 'Trello'), ('email', 'Email'), ('website', 'Website')], max_length=32, verbose_name='system')), + ('value', models.BooleanField(verbose_name='access')), + ('member', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='internal.member', verbose_name='member')), + ], + ), + migrations.RunPython( + code=update_user_card_from_member, + reverse_code=reverse_update_user_card_from_member, + ), + migrations.RemoveField( + model_name='member', + name='card_number', + ), + migrations.CreateModel( + name='Secret', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', web.multilingual.modelfields.MultiLingualTextField(max_length=100, unique=True, verbose_name='title')), + ('content', web.multilingual.modelfields.MultiLingualRichTextUploadingField(verbose_name='description')), + ('last_modified', models.DateTimeField(auto_now=True, verbose_name='last modified')), + ], + ), + migrations.AlterField( + model_name='member', + name='comment', + field=models.TextField(blank=True, verbose_name='comment'), + ), + migrations.AlterField( + model_name='member', + name='email', + field=models.EmailField(blank=True, max_length=254, verbose_name='contact email'), + ), + migrations.AlterField( + model_name='member', + name='phone_number', + field=phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=32, region=None, verbose_name='phone number'), + ), + migrations.AlterField( + model_name='member', + name='reason_quit', + field=models.TextField(blank=True, verbose_name='reason quit'), + ), + migrations.AlterField( + model_name='member', + name='role', + field=web.modelfields.UnlimitedCharField(blank=True, verbose_name='role'), + ), + migrations.AlterField( + model_name='member', + name='study_program', + field=web.modelfields.UnlimitedCharField(blank=True, verbose_name='study program'), + ), + migrations.AddConstraint( + model_name='systemaccess', + constraint=models.UniqueConstraint(fields=('name', 'member'), name='systemaccess_unique_name_per_member'), + ), + migrations.AlterModelOptions( + name='systemaccess', + options={'verbose_name': 'system access', 'verbose_name_plural': 'system accesses'}, + ), + migrations.AlterField( + model_name='member', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='secret', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='systemaccess', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='member', + name='committees', + field=models.ManyToManyField(blank=True, related_name='members', to='groups.committee', verbose_name='committees'), + ), + migrations.AlterField( + model_name='member', + name='user', + field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='member', to=settings.AUTH_USER_MODEL, verbose_name='user'), + ), + migrations.AlterField( + model_name='systemaccess', + name='member', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='system_accesses', to='internal.member', verbose_name='member'), + ), + migrations.AddField( + model_name='secret', + name='priority', + field=models.IntegerField(blank=True, help_text='If specified, the secrets are sorted ascending by this value.', null=True, verbose_name='priority'), + ), + migrations.AddField( + model_name='member', + name='last_modified', + field=models.DateTimeField(auto_now=True, default=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), verbose_name='last modified'), + preserve_default=False, + ), + migrations.AddField( + model_name='systemaccess', + name='last_modified', + field=models.DateTimeField(auto_now=True, default=datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), verbose_name='last modified'), + preserve_default=False, + ), + migrations.RenameField( + model_name='member', + old_name='date_quit', + new_name='date_quit_or_retired', + ), + migrations.AlterField( + model_name='member', + name='date_quit_or_retired', + field=models.DateField(blank=True, null=True, verbose_name='date quit or retired'), + ), + migrations.RenameField( + model_name='member', + old_name='email', + new_name='contact_email', + ), + migrations.AddField( + model_name='member', + name='discord_username', + field=web.modelfields.UnlimitedCharField(blank=True, help_text='The username must include the hashtag and the four digits at the end.', validators=[django.core.validators.RegexValidator(re.compile('^(.+)#([0-9]{4})$'), 'Enter a valid Discord username – including the hashtag and the four digits at the end.')], verbose_name='Discord username'), + ), + migrations.AddField( + model_name='member', + name='github_username', + field=web.modelfields.UnlimitedCharField(blank=True, verbose_name='GitHub username'), + ), + migrations.AddField( + model_name='member', + name='gmail', + field=models.EmailField(blank=True, max_length=254, verbose_name='Gmail'), + ), + migrations.AddField( + model_name='member', + name='MAKE_email', + field=models.EmailField(blank=True, max_length=254, validators=[internal.validators.WhitelistedEmailValidator(valid_domains=['makentnu.no'])], verbose_name='MAKE email'), + ), + migrations.AddField( + model_name='member', + name='minecraft_username', + field=web.modelfields.UnlimitedCharField(blank=True, verbose_name='Minecraft username'), + ), + migrations.AddField( + model_name='member', + name='ntnu_starting_semester', + field=internal.modelfields.SemesterField(blank=True, help_text='Must be in the format [V/H][year], e.g. “V17” or “H2017”.', null=True, verbose_name='starting semester at NTNU'), + ), + migrations.AlterModelOptions( + name='member', + options={'permissions': (('is_internal', 'Is a member of MAKE NTNU'), ('can_edit_group_membership', 'Can edit the groups a member is part of, including (de)activation'), ('can_change_rich_text_source', "Can change rich text fields' HTML source code directly (including adding