Skip to content

Commit 8648b01

Browse files
Merge pull request #2520 from IFRCGo/feature/dref3-changes
DREF3 changes
2 parents a9fe7da + 6c379e1 commit 8648b01

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

dref/serializers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,9 +1622,9 @@ def get_type_of_onset(self, obj):
16221622
return Dref.OnsetType(type_of_onset).label
16231623

16241624
def get_crisis_categorization(self, obj):
1625-
if obj.disaster_category:
1625+
if hasattr(obj, "disaster_category") and obj.disaster_category is not None:
16261626
return Dref.DisasterCategory(obj.disaster_category).label
1627-
return "Unknown category"
1627+
return "Yellow (?)"
16281628

16291629
def get_amount_approved(self, obj):
16301630
if hasattr(obj, "amount_requested"):
@@ -1677,9 +1677,9 @@ def get_affected_people(self, obj):
16771677

16781678
def get_targeted_people(self, obj):
16791679
t = type(obj).__name__
1680-
if t == "Dref" and hasattr(obj, "total_targeted_population"):
1680+
if t != "DrefOperationalUpdate" and hasattr(obj, "total_targeted_population"): # A + FR:
16811681
return obj.total_targeted_population
1682-
if t != "Dref" and hasattr(obj, "number_of_people_targeted"): # OU + FR:
1682+
if t == "DrefOperationalUpdate" and hasattr(obj, "number_of_people_targeted"):
16831683
return obj.number_of_people_targeted
16841684

16851685
def get_beneficiaries_assisted(self, obj):

dref/views.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def get_objects_by_appeal_code(self, appeal_code):
359359
drefs = (
360360
Dref.objects.filter(appeal_code=appeal_code)
361361
.prefetch_related("planned_interventions", "needs_identified", "national_society_actions", "users")
362-
.order_by("-created_at")
362+
.order_by("created_at")
363363
.distinct()
364364
)
365365
drefs = filter_dref_queryset_by_user_access(user, drefs)
@@ -370,7 +370,7 @@ def get_objects_by_appeal_code(self, appeal_code):
370370
operational_updates = (
371371
DrefOperationalUpdate.objects.filter(appeal_code=appeal_code)
372372
.prefetch_related("planned_interventions", "needs_identified", "national_society_actions", "users")
373-
.order_by("-created_at")
373+
.order_by("created_at")
374374
.distinct()
375375
)
376376
operational_updates = filter_dref_queryset_by_user_access(user, operational_updates)
@@ -380,7 +380,7 @@ def get_objects_by_appeal_code(self, appeal_code):
380380
final_reports = (
381381
DrefFinalReport.objects.filter(appeal_code=appeal_code)
382382
.prefetch_related("planned_interventions", "needs_identified", "national_society_actions", "users")
383-
.order_by("-created_at")
383+
.order_by("created_at")
384384
.distinct()
385385
)
386386
final_reports = filter_dref_queryset_by_user_access(user, final_reports)
@@ -399,14 +399,16 @@ def retrieve(self, request, *args, **kwargs):
399399

400400
serialized_data = []
401401
ops_update_count = 0
402-
a = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Nineth", "Tenth"]
402+
allocation_count = 1 # Dref Application is always the first allocation
403+
a = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth"]
403404
for instance in instances:
404405
if isinstance(instance, Dref):
405406
serializer = Dref3Serializer(instance, context={"stage": "Application", "allocation": a[0]})
406407
elif isinstance(instance, DrefOperationalUpdate):
407408
ops_update_count += 1
408-
if instance.additional_allocation and len(a) > ops_update_count:
409-
allocation = a[ops_update_count]
409+
if instance.additional_allocation and len(a) > allocation_count:
410+
allocation = a[allocation_count]
411+
allocation_count += 1
410412
else:
411413
allocation = "No allocation"
412414
serializer = DrefOperationalUpdate3Serializer(

0 commit comments

Comments
 (0)