|
| 1 | +# Generated by Django 4.2.21 on 2025-07-07 16:18 |
| 2 | + |
| 3 | +from django.conf import settings |
| 4 | +from django.db import migrations, models |
| 5 | +from django.utils import translation |
| 6 | +import django.db.models.deletion |
| 7 | + |
| 8 | + |
| 9 | +def connect_contact_person_to_account(apps, schema_editor): |
| 10 | + ContactPerson = apps.get_model("core", "ContactPerson") |
| 11 | + Account = apps.get_model("core", "Account") |
| 12 | + languages = ['cy', 'de', 'en', 'en-us', 'en_us', 'es', 'fr', 'it', 'nl'] |
| 13 | + for contact_person in ContactPerson.objects.all(): |
| 14 | + account, created = Account.objects.get_or_create( |
| 15 | + username=contact_person.email.lower(), |
| 16 | + defaults={ |
| 17 | + 'first_name': ' '.join(contact_person.name.split()[:-1]), |
| 18 | + 'last_name': contact_person.name.split()[-1], |
| 19 | + 'email': contact_person.email, |
| 20 | + } |
| 21 | + ) |
| 22 | + contact_person.account = account |
| 23 | + for language in languages: |
| 24 | + with translation.override(language): |
| 25 | + language_var = "name_{}".format(language) |
| 26 | + setattr(contact_person, language_var, '') |
| 27 | + contact_person.email = '' |
| 28 | + contact_person.save() |
| 29 | + |
| 30 | + |
| 31 | +class Migration(migrations.Migration): |
| 32 | + |
| 33 | + dependencies = [ |
| 34 | + ('contenttypes', '0002_remove_content_type_name'), |
| 35 | + ('core', '0107_alter_controlledaffiliation_options_and_more'), |
| 36 | + ] |
| 37 | + |
| 38 | + operations = [ |
| 39 | + migrations.RenameModel( |
| 40 | + old_name='Contact', |
| 41 | + new_name='ContactMessage', |
| 42 | + ), |
| 43 | + migrations.RenameModel( |
| 44 | + old_name='Contacts', |
| 45 | + new_name='ContactPerson', |
| 46 | + ), |
| 47 | + migrations.AddField( |
| 48 | + model_name='contactperson', |
| 49 | + name='account', |
| 50 | + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), |
| 51 | + ), |
| 52 | + migrations.AlterField( |
| 53 | + model_name='contactperson', |
| 54 | + name='email', |
| 55 | + field=models.EmailField(blank=True, help_text="The 'email' field is deprecated. Use 'account.email'.", max_length=254), |
| 56 | + ), |
| 57 | + migrations.AlterField( |
| 58 | + model_name='contactperson', |
| 59 | + name='name', |
| 60 | + field=models.CharField(blank=True, help_text="The 'name' field is deprecated. Use 'account.full_name'.", max_length=300), |
| 61 | + ), |
| 62 | + migrations.AlterField( |
| 63 | + model_name='contactperson', |
| 64 | + name='name_cy', |
| 65 | + field=models.CharField(blank=True, help_text="The 'name' field is deprecated. Use 'account.full_name'.", max_length=300, null=True), |
| 66 | + ), |
| 67 | + migrations.AlterField( |
| 68 | + model_name='contactperson', |
| 69 | + name='name_de', |
| 70 | + field=models.CharField(blank=True, help_text="The 'name' field is deprecated. Use 'account.full_name'.", max_length=300, null=True), |
| 71 | + ), |
| 72 | + migrations.AlterField( |
| 73 | + model_name='contactperson', |
| 74 | + name='name_en', |
| 75 | + field=models.CharField(blank=True, help_text="The 'name' field is deprecated. Use 'account.full_name'.", max_length=300, null=True), |
| 76 | + ), |
| 77 | + migrations.AlterField( |
| 78 | + model_name='contactperson', |
| 79 | + name='name_en_us', |
| 80 | + field=models.CharField(blank=True, help_text="The 'name' field is deprecated. Use 'account.full_name'.", max_length=300, null=True), |
| 81 | + ), |
| 82 | + migrations.AlterField( |
| 83 | + model_name='contactperson', |
| 84 | + name='name_es', |
| 85 | + field=models.CharField(blank=True, help_text="The 'name' field is deprecated. Use 'account.full_name'.", max_length=300, null=True), |
| 86 | + ), |
| 87 | + migrations.AlterField( |
| 88 | + model_name='contactperson', |
| 89 | + name='name_fr', |
| 90 | + field=models.CharField(blank=True, help_text="The 'name' field is deprecated. Use 'account.full_name'.", max_length=300, null=True), |
| 91 | + ), |
| 92 | + migrations.AlterField( |
| 93 | + model_name='contactperson', |
| 94 | + name='name_nl', |
| 95 | + field=models.CharField(blank=True, help_text="The 'name' field is deprecated. Use 'account.full_name'.", max_length=300, null=True), |
| 96 | + ), |
| 97 | + migrations.AlterModelOptions( |
| 98 | + name='contactmessage', |
| 99 | + options={}, |
| 100 | + ), |
| 101 | + migrations.AlterModelOptions( |
| 102 | + name='contactperson', |
| 103 | + options={'ordering': ('sequence',)}, |
| 104 | + ), |
| 105 | + migrations.RunPython( |
| 106 | + connect_contact_person_to_account, |
| 107 | + reverse_code=migrations.RunPython.noop, |
| 108 | + ) |
| 109 | + ] |
0 commit comments