Skip to content

Commit d5616b4

Browse files
committed
Merge pull request #2606 from IFRCGo/fix/export-url-eap
EAP: Update Export URLs with diff and versions
2 parents 5b7ee80 + 28e59da commit d5616b4

8 files changed

Lines changed: 267 additions & 56 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 4.2.26 on 2025-12-04 09:06
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("api", "0228_alter_export_export_type"),
9+
]
10+
11+
operations = [
12+
migrations.AlterField(
13+
model_name="export",
14+
name="export_type",
15+
field=models.CharField(
16+
choices=[
17+
("dref-applications", "DREF Application"),
18+
("dref-operational-updates", "DREF Operational Update"),
19+
("dref-final-reports", "DREF Final Report"),
20+
("old-dref-final-reports", "Old DREF Final Report"),
21+
("per", "Per"),
22+
("simplified", "Simplified EAP"),
23+
("full", "Full EAP"),
24+
],
25+
max_length=255,
26+
verbose_name="Export Type",
27+
),
28+
),
29+
]

api/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,8 +2560,8 @@ class ExportType(models.TextChoices):
25602560
FINAL_REPORT = "dref-final-reports", _("DREF Final Report")
25612561
OLD_FINAL_REPORT = "old-dref-final-reports", _("Old DREF Final Report")
25622562
PER = "per", _("Per")
2563-
SIMPLIFIED_EAP = "simplified-eap", _("Simplified EAP")
2564-
FULL_EAP = "full-eap", _("Full EAP")
2563+
SIMPLIFIED_EAP = "simplified", _("Simplified EAP")
2564+
FULL_EAP = "full", _("Full EAP")
25652565

25662566
export_id = models.IntegerField(verbose_name=_("Export Id"))
25672567
export_type = models.CharField(verbose_name=_("Export Type"), max_length=255, choices=ExportType.choices)

api/serializers.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from api.utils import CountryValidator, RegionValidator
1616
from deployments.models import EmergencyProject, Personnel, PersonnelDeployment
1717
from dref.models import Dref, DrefFinalReport, DrefOperationalUpdate
18-
from eap.models import FullEAP, SimplifiedEAP
18+
from eap.models import EAPRegistration, FullEAP, SimplifiedEAP
1919
from lang.models import String
2020
from lang.serializers import ModelSerializer
2121
from local_units.models import DelegationOffice
@@ -2544,6 +2544,11 @@ class ExportSerializer(serializers.ModelSerializer):
25442544
status_display = serializers.CharField(source="get_status_display", read_only=True)
25452545
# NOTE: is_pga is used to determine if the export contains PGA or not
25462546
is_pga = serializers.BooleanField(default=False, required=False, write_only=True)
2547+
# NOTE: diff is used to determine if the export is requested for diff view or not
2548+
# Currently only used for EAP exports
2549+
diff = serializers.BooleanField(default=False, required=False, write_only=True)
2550+
# NOTE: Version of a EAP export being requested, only applicable for full and simplified EAP exports
2551+
version = serializers.IntegerField(required=False, write_only=True)
25472552

25482553
class Meta:
25492554
model = Export
@@ -2559,6 +2564,7 @@ def create(self, validated_data):
25592564
export_id = validated_data.get("export_id")
25602565
export_type = validated_data.get("export_type")
25612566
country_id = validated_data.get("per_country")
2567+
version = validated_data.pop("version", None)
25622568
if export_type == Export.ExportType.DREF:
25632569
title = Dref.objects.filter(id=export_id).first().title
25642570
elif export_type == Export.ExportType.OPS_UPDATE:
@@ -2569,19 +2575,62 @@ def create(self, validated_data):
25692575
overview = Overview.objects.filter(id=export_id).first()
25702576
title = f"{overview.country.name}-preparedness-{overview.get_phase_display()}"
25712577
elif export_type == Export.ExportType.SIMPLIFIED_EAP:
2572-
simplified_eap = SimplifiedEAP.objects.filter(id=export_id).first()
2578+
if version:
2579+
simplified_eap = SimplifiedEAP.objects.filter(
2580+
eap_registration=export_id,
2581+
version=version,
2582+
).first()
2583+
if not simplified_eap:
2584+
raise serializers.ValidationError("No Simplified EAP found for the given EAP Registration ID and version")
2585+
else:
2586+
eap_registration = EAPRegistration.objects.filter(id=export_id).first()
2587+
if not eap_registration:
2588+
raise serializers.ValidationError("No EAP Registration found for the given ID")
2589+
2590+
simplified_eap = eap_registration.latest_simplified_eap
2591+
if not simplified_eap:
2592+
serializers.ValidationError("No Simplified EAP found for the given EAP Registration ID")
2593+
25732594
title = (
25742595
f"{simplified_eap.eap_registration.national_society.name}-{simplified_eap.eap_registration.disaster_type.name}"
25752596
)
25762597
elif export_type == Export.ExportType.FULL_EAP:
2577-
full_eap = FullEAP.objects.filter(id=export_id).first()
2598+
if version:
2599+
full_eap = FullEAP.objects.filter(
2600+
eap_registration=export_id,
2601+
version=version,
2602+
).first()
2603+
if not full_eap:
2604+
raise serializers.ValidationError("No Full EAP found for the given EAP Registration ID and version")
2605+
else:
2606+
eap_registration = EAPRegistration.objects.filter(id=export_id).first()
2607+
if not eap_registration:
2608+
raise serializers.ValidationError("No EAP Registration found for the given ID")
2609+
2610+
full_eap = eap_registration.latest_full_eap
2611+
if not full_eap:
2612+
serializers.ValidationError("No Full EAP found for the given EAP Registration ID")
2613+
25782614
title = f"{full_eap.eap_registration.national_society.name}-{full_eap.eap_registration.disaster_type.name}"
25792615
else:
25802616
title = "Export"
25812617
user = self.context["request"].user
25822618

25832619
if export_type == Export.ExportType.PER:
25842620
validated_data["url"] = f"{settings.GO_WEB_INTERNAL_URL}/countries/{country_id}/{export_type}/{export_id}/export/"
2621+
2622+
elif export_type in [
2623+
Export.ExportType.SIMPLIFIED_EAP,
2624+
Export.ExportType.FULL_EAP,
2625+
]:
2626+
validated_data["url"] = f"{settings.GO_WEB_INTERNAL_URL}/eap/{export_id}/{export_type}/export/"
2627+
# NOTE: EAP exports with diff view only for EAPs exports
2628+
if version:
2629+
validated_data["url"] += f"?version={version}"
2630+
diff = validated_data.pop("diff")
2631+
if diff:
2632+
validated_data["url"] += "&diff=true" if version else "?diff=true"
2633+
25852634
else:
25862635
validated_data["url"] = f"{settings.GO_WEB_INTERNAL_URL}/{export_type}/{export_id}/export/"
25872636

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Generated by Django 4.2.26 on 2025-12-15 06:33
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("eap", "0010_eapaction_eapimpact_indicator_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="fulleap",
15+
name="updated_checklist_file",
16+
field=models.ForeignKey(
17+
blank=True,
18+
null=True,
19+
on_delete=django.db.models.deletion.SET_NULL,
20+
to="eap.eapfile",
21+
verbose_name="Updated Review Checklist File",
22+
),
23+
),
24+
migrations.AlterField(
25+
model_name="simplifiedeap",
26+
name="updated_checklist_file",
27+
field=models.ForeignKey(
28+
blank=True,
29+
null=True,
30+
on_delete=django.db.models.deletion.SET_NULL,
31+
to="eap.eapfile",
32+
verbose_name="Updated Review Checklist File",
33+
),
34+
),
35+
]

eap/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,10 @@ class CommonEAPFields(models.Model):
879879
)
880880

881881
# Review Checklist
882-
updated_checklist_file = SecureFileField(
883-
verbose_name=_("Updated Checklist File"),
884-
upload_to="eap/files/",
882+
updated_checklist_file = models.ForeignKey[EAPFile | None, EAPFile | None](
883+
EAPFile,
884+
on_delete=models.SET_NULL,
885+
verbose_name=_("Updated Review Checklist File"),
885886
null=True,
886887
blank=True,
887888
)

eap/serializers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class Meta:
9898
"version",
9999
"is_locked",
100100
"updated_checklist_file",
101+
"created_at",
102+
"modified_at",
101103
]
102104

103105

@@ -118,6 +120,8 @@ class Meta:
118120
"version",
119121
"is_locked",
120122
"updated_checklist_file",
123+
"created_at",
124+
"modified_at",
121125
]
122126

123127

@@ -143,6 +147,8 @@ class Meta:
143147
"requirement_cost",
144148
"activated_at",
145149
"approved_at",
150+
"created_at",
151+
"modified_at",
146152
]
147153

148154

@@ -421,8 +427,8 @@ def validate_updated_checklist_file(self, file):
421427
if file is None:
422428
return
423429

424-
validate_file_extention(file.name, ALLOWED_FILE_EXTENTIONS)
425-
validate_file_type(file)
430+
validate_file_extention(file.file.name, ALLOWED_FILE_EXTENTIONS)
431+
validate_file_type(file.file)
426432
return file
427433

428434
def validate_images_field(self, field_name, images):

0 commit comments

Comments
 (0)