Skip to content

Commit 860cfda

Browse files
committed
Hide some affected values
1 parent 708991f commit 860cfda

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

api/drf_views.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,19 @@ def retrieve(self, request, pk=None, *args, **kwargs):
446446
raise BadRequest('Emergency ID or Slug parameters are missing')
447447

448448
serializer = self.get_serializer(instance)
449+
450+
# Hide the "affected" values that are kept only for history – see (¤) in other code parts
451+
if 'field_reports' in serializer.data:
452+
for j, fr in enumerate(serializer.data['field_reports']):
453+
if 'recent_affected' in fr: # should always be True
454+
for i, field in enumerate([
455+
'num_affected', 'gov_num_affected', 'other_num_affected',
456+
'num_potentially_affected', 'gov_num_potentially_affected', 'other_num_potentially_affected']):
457+
if fr['recent_affected'] - 1 != i and field in serializer.data['field_reports'][j]:
458+
del serializer.data['field_reports'][j][field]
459+
del serializer.data['field_reports'][j]['recent_affected']
460+
461+
449462
return Response(serializer.data)
450463

451464
@action(methods=['get'], detail=False, url_path='mini')
@@ -722,7 +735,7 @@ def serialize(self, data, instance=None):
722735
else:
723736
data['visibility'] = VisibilityChoices.MEMBERSHIP
724737

725-
# Set RecentAffected according to the sent _affected key
738+
# Set RecentAffected according to the sent _affected key – see (¤) in other code parts
726739
if 'status' in data and data['status'] == FieldReport.Status.EW: # Early Warning
727740
if 'num_potentially_affected' in data:
728741
data['recent_affected'] = FieldReport.RecentAffected.RCRC_POTENTIALLY

api/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ class RecentAffected(models.IntegerChoices):
11651165
RCRC_POTENTIALLY = 4, _('Red Cross / Red Crescent, potentially')
11661166
GOVERNMENT_POTENTIALLY = 5, _('Government, potentially')
11671167
OTHER_POTENTIALLY = 6, _('Other, potentially')
1168-
# Take care, these values are connected to (¤) in serializers.py, search it!
1168+
# Take care of these values – see (¤) in other code parts
11691169

11701170
user = models.ForeignKey(
11711171
settings.AUTH_USER_MODEL, verbose_name=_('user'), related_name='user',

api/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ class Meta:
451451
'other_affected_pop_centres', 'epi_cases', 'epi_suspected_cases', 'epi_probable_cases', 'epi_confirmed_cases',
452452
'epi_figures_source', 'epi_figures_source_display', 'epi_cases_since_last_fr', 'epi_deaths_since_last_fr',
453453
'epi_notes_since_last_fr', 'visibility', 'visibility_display', 'request_assistance', 'ns_request_assistance',
454-
'notes_health', 'notes_ns', 'notes_socioeco'
454+
'notes_health', 'notes_ns', 'notes_socioeco', 'recent_affected'
455455
)
456456

457457

@@ -1067,7 +1067,7 @@ def __init__(self, *args, **kwargs):
10671067
'num_affected', 'gov_num_affected', 'other_num_affected',
10681068
'num_potentially_affected', 'gov_num_potentially_affected', 'other_num_potentially_affected']):
10691069
# We allow only 1 of these _affected values ^, pointed by RecentAffected. The other 5 gets 0 on client side.
1070-
# Attention! This indexing is related to RecentAffected values – in models.py: (¤)
1070+
# About "recent_affected - 1" as index see (¤) in other code parts:
10711071
if self.instance.recent_affected - 1 != i:
10721072
self.fields.pop(field)
10731073

utils/erp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def push_fr_data(data, retired=False):
6060
else:
6161
InitialRequestType, InitialRequestValue = "Empty", 0
6262

63-
# About "RecentAffected - 1" as index check (¤) in api/models.py and serializer.py :
63+
# About "RecentAffected - 1" as index see (¤) in other code parts:
6464
index = data.recent_affected - 1 if data.recent_affected > 0 else 0
6565
# In Early Warning we use "potentially affected", not the normal "affected" figure. Should be only one:
6666
NumberOfPeopleAffected = [

0 commit comments

Comments
 (0)