|
1 | | -# Generated by Django 4.2.19 on 2025-11-05 08:22 |
| 1 | +# Generated by Django 4.2.19 on 2025-11-05 11:03 |
2 | 2 |
|
3 | 3 | from django.db import migrations, models |
4 | 4 |
|
| 5 | +def update_status(apps, schema_editor): |
| 6 | + """ |
| 7 | + Update old status to new workflow: |
| 8 | + - Not published or IN_PROGRESS → DRAFT |
| 9 | + - Published or COMPLETED → APPROVED |
| 10 | + Applies to Dref, DrefOperationalUpdate, and DrefFinalReport. |
| 11 | + """ |
| 12 | + models = [ |
| 13 | + "Dref", |
| 14 | + "DrefOperationalUpdate", |
| 15 | + "DrefFinalReport", |
| 16 | + ] |
| 17 | + for model_name in models: |
| 18 | + Model = apps.get_model("dref", model_name) |
| 19 | + Model.objects.filter(is_published=True).update(status=4) # Published → APPROVED |
| 20 | + Model.objects.filter(is_published=False).update(status=1) # Not published → DRAFT |
| 21 | + |
| 22 | +def update_starting_language(apps, schema_editor): |
| 23 | + """ |
| 24 | + Populate the starting_language field with 'en' for all existing records. |
| 25 | + """ |
| 26 | + models = [ |
| 27 | + "Dref", |
| 28 | + "DrefOperationalUpdate", |
| 29 | + "DrefFinalReport", |
| 30 | + ] |
| 31 | + for model_name in models: |
| 32 | + Model = apps.get_model("dref", model_name) |
| 33 | + Model.objects.update(starting_language="en") |
| 34 | + |
5 | 35 |
|
6 | 36 | class Migration(migrations.Migration): |
7 | 37 |
|
8 | 38 | dependencies = [ |
9 | | - ('dref', '0085_remove_dref_is_published_and_more'), |
| 39 | + ('dref', '0083_dreffinalreport_total_operation_timeframe_imminent'), |
10 | 40 | ] |
11 | 41 |
|
12 | 42 | operations = [ |
| 43 | + migrations.RunPython(update_status,reverse_code=migrations.RunPython.noop), |
13 | 44 | migrations.AddField( |
14 | 45 | model_name='dref', |
15 | 46 | name='addressed_humanitarian_impacts_ar', |
@@ -70,4 +101,47 @@ class Migration(migrations.Migration): |
70 | 101 | name='hazard_vulnerabilities_and_risks_fr', |
71 | 102 | field=models.TextField(blank=True, help_text='Explain the underlying vulnerabilities and risks the hazard poses for at-risk communities?', null=True, verbose_name='Hazard Vulnerabilities and Risks'), |
72 | 103 | ), |
| 104 | + migrations.AddField( |
| 105 | + model_name='dref', |
| 106 | + name='starting_language', |
| 107 | + field=models.CharField(blank=True, help_text='The language in which this record was first created.', null=True, verbose_name='Starting language'), |
| 108 | + ), |
| 109 | + migrations.AddField( |
| 110 | + model_name='dreffinalreport', |
| 111 | + name='starting_language', |
| 112 | + field=models.CharField(blank=True, help_text='The language in which this record was first created.', null=True, verbose_name='Starting language'), |
| 113 | + ), |
| 114 | + migrations.AddField( |
| 115 | + model_name='drefoperationalupdate', |
| 116 | + name='starting_language', |
| 117 | + field=models.CharField(blank=True, help_text='The language in which this record was first created.', null=True, verbose_name='Starting language'), |
| 118 | + ), |
| 119 | + migrations.AlterField( |
| 120 | + model_name='dref', |
| 121 | + name='status', |
| 122 | + field=models.IntegerField(choices=[(1, 'Draft'), (2, 'Finalizing'), (3, 'Finalized'), (4, 'Approved'), (5, 'Finalizing Failed')], default=1, verbose_name='status'), |
| 123 | + ), |
| 124 | + migrations.AlterField( |
| 125 | + model_name='dreffinalreport', |
| 126 | + name='status', |
| 127 | + field=models.IntegerField(choices=[(1, 'Draft'), (2, 'Finalizing'), (3, 'Finalized'), (4, 'Approved'), (5, 'Finalizing Failed')], default=1, verbose_name='status'), |
| 128 | + ), |
| 129 | + migrations.AlterField( |
| 130 | + model_name='drefoperationalupdate', |
| 131 | + name='status', |
| 132 | + field=models.IntegerField(choices=[(1, 'Draft'), (2, 'Finalizing'), (3, 'Finalized'), (4, 'Approved'), (5, 'Finalizing Failed')], default=1, verbose_name='status'), |
| 133 | + ), |
| 134 | + migrations.RemoveField( |
| 135 | + model_name='dref', |
| 136 | + name='is_published', |
| 137 | + ), |
| 138 | + migrations.RemoveField( |
| 139 | + model_name='dreffinalreport', |
| 140 | + name='is_published', |
| 141 | + ), |
| 142 | + migrations.RemoveField( |
| 143 | + model_name='drefoperationalupdate', |
| 144 | + name='is_published', |
| 145 | + ), |
| 146 | + migrations.RunPython(update_starting_language,reverse_code=migrations.RunPython.noop), |
73 | 147 | ] |
0 commit comments