-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2388 from IFRCGo/project/field-report-translations
Feat: FieldReport and Emergencies Translation
- Loading branch information
Showing
17 changed files
with
522 additions
and
407 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
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
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,79 @@ | ||
import re | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.db.models.expressions import Exists, OuterRef | ||
|
||
from api.models import FieldReport | ||
from main.managers import BulkUpdateManager | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Migrate legacy FieldReport data to populate fr_num" | ||
|
||
def handle(self, *args, **kwargs): | ||
|
||
suffix_pattern = re.compile(r"#\s*(\d+)") | ||
|
||
reports = ( | ||
FieldReport.objects.filter(event__isnull=False, countries__isnull=False, summary__icontains="#") | ||
.annotate( | ||
has_fr_num=Exists( | ||
FieldReport.objects.filter(event=OuterRef("event"), countries=OuterRef("countries"), fr_num__isnull=False) | ||
) | ||
) | ||
.exclude(has_fr_num=True) | ||
) | ||
|
||
report_count = reports.count() | ||
self.stdout.write(self.style.NOTICE(f"Found {report_count} FieldReports to process")) | ||
|
||
if report_count == 0: | ||
self.stdout.write(self.style.WARNING("No FieldReports found to process")) | ||
return | ||
|
||
event_country_data = {} | ||
|
||
for report in reports.iterator(): | ||
country = report.countries.first() | ||
|
||
if country is None: | ||
self.stdout.write(self.style.ERROR(f"FieldReport ID: ({report.id}) has no associated country.")) | ||
continue | ||
|
||
summary_match = suffix_pattern.search(report.summary) | ||
derived_fr_num = int(summary_match.group(1)) if summary_match else 0 | ||
|
||
max_fr_num = max(derived_fr_num, report.fr_num or 0) | ||
key = (report.event.id, country.id) | ||
|
||
group_data = event_country_data.get( | ||
key, | ||
{ | ||
"highest_fr_num": 0, | ||
"report_highest_fr": None, | ||
}, | ||
) | ||
|
||
if max_fr_num > group_data["highest_fr_num"]: | ||
group_data["highest_fr_num"] = max_fr_num | ||
group_data["report_highest_fr"] = report | ||
|
||
event_country_data[key] = group_data | ||
|
||
bulk_mgr = BulkUpdateManager(update_fields=["fr_num"]) | ||
|
||
for data in event_country_data.values(): | ||
highest_report = data["report_highest_fr"] | ||
highest_fr_num = data["highest_fr_num"] | ||
if highest_report: | ||
self.stdout.write( | ||
self.style.NOTICE(f"Preparing to update FieldReport ID:({highest_report.id}) with fr_num:({highest_fr_num}).") | ||
) | ||
bulk_mgr.add( | ||
FieldReport( | ||
id=highest_report.id, | ||
fr_num=highest_fr_num, | ||
) | ||
) | ||
bulk_mgr.done() | ||
self.stdout.write(self.style.SUCCESS("FieldReport migration completed successfully.")) |
68 changes: 68 additions & 0 deletions
68
api/migrations/0215_event_title_event_title_ar_event_title_en_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,68 @@ | ||
# Generated by Django 4.2.16 on 2024-11-20 09:20 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("api", "0214_alter_profile_limit_access_to_guest"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="event", | ||
name="title", | ||
field=models.CharField(blank=True, max_length=256), | ||
), | ||
migrations.AddField( | ||
model_name="event", | ||
name="title_ar", | ||
field=models.CharField(blank=True, max_length=256, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="event", | ||
name="title_en", | ||
field=models.CharField(blank=True, max_length=256, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="event", | ||
name="title_es", | ||
field=models.CharField(blank=True, max_length=256, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="event", | ||
name="title_fr", | ||
field=models.CharField(blank=True, max_length=256, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="fieldreport", | ||
name="fr_num", | ||
field=models.IntegerField(blank=True, null=True, verbose_name="field report number"), | ||
), | ||
migrations.AddField( | ||
model_name="fieldreport", | ||
name="title", | ||
field=models.CharField(blank=True, max_length=256), | ||
), | ||
migrations.AddField( | ||
model_name="fieldreport", | ||
name="title_ar", | ||
field=models.CharField(blank=True, max_length=256, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="fieldreport", | ||
name="title_en", | ||
field=models.CharField(blank=True, max_length=256, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="fieldreport", | ||
name="title_es", | ||
field=models.CharField(blank=True, max_length=256, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="fieldreport", | ||
name="title_fr", | ||
field=models.CharField(blank=True, max_length=256, null=True), | ||
), | ||
] |
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,13 @@ | ||
# Generated by Django 4.2.16 on 2025-01-07 10:19 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("api", "0215_event_title_event_title_ar_event_title_en_and_more"), | ||
("api", "0216_district_emma_id_district_fips_code_district_nuts1_and_more"), | ||
] | ||
|
||
operations = [] |
Oops, something went wrong.