Skip to content

Commit 2d835b7

Browse files
Merge pull request #1855 from IFRCGo/feature/molnix-1812
Feature/molnix 1812
2 parents 844ccfb + 2286854 commit 2d835b7

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

deployments/drf_views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def get_renderer_context(self):
222222
"deployment.event_deployed_to.countries.region",
223223
"role",
224224
"type",
225+
"surge_alert_id",
225226
]
226227
if not self.request.user.is_anonymous:
227228
context["header"] += ["name"]
@@ -275,6 +276,7 @@ def get_renderer_context(self):
275276
context["labels"]["country_from.iso3"] = "deployed_from_iso3"
276277
context["labels"]["country_from.society_name"] = "deployed_from_nationalsociety"
277278
context["labels"]["country_from.region"] = "deployed_from_regionname"
279+
context["labels"]["surge_alert_id"] = "surge_alert_id"
278280

279281
# https://github.com/mjumbewu/django-rest-framework-csv/blob/master/rest_framework_csv/renderers.py#L226-L229 uses bom when required:
280282
context["bom"] = True

deployments/forms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def _parse_integer(integer):
227227
disaster_type_id = disaster_types[disaster_type_name.lower()] if disaster_type_name else None
228228

229229
row_errors = {}
230+
project_country = Country.objects.filter(name__iexact=country_name).first()
230231
project_districts = []
231232
if district_names:
232233
project_districts = list(District.objects.filter(
@@ -240,12 +241,11 @@ def _parse_integer(integer):
240241
).all())
241242
# Check if all district_names is available in db
242243
if len(project_districts) == len(district_names):
243-
project_country = project_districts[0].country
244+
if project_country is None: # in case of we did not find a proper country name, trying to know it:
245+
project_country = project_districts[0].country
244246
else:
245-
# District list can be empty. If not empty, we get country name from the first one.
246-
project_country = None
247-
else:
248-
project_country = Country.objects.filter(name__iexact=country_name).first()
247+
# but it can not happen that some of the given district-names cannot be found:
248+
row_errors['project_districts'] = [f'Some given district_names are not available. "{district_names}"']
249249

250250
# A validation error will be raised. This is just a custom message
251251
if project_country is None:

deployments/serializers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class Meta:
144144
fields = (
145145
'start_date', 'end_date', 'role', 'type', 'country_from', 'country_to',
146146
'deployment', 'molnix_id', 'molnix_tags', 'is_active', 'id',
147+
'surge_alert_id',
147148
'name', # plus
148149
)
149150

@@ -160,6 +161,7 @@ class Meta:
160161
fields = (
161162
'start_date', 'end_date', 'role', 'type', 'country_from', 'country_to',
162163
'deployment', 'molnix_id', 'molnix_tags', 'is_active', 'id',
164+
'surge_alert_id',
163165
)
164166

165167

@@ -175,10 +177,12 @@ class Meta:
175177
fields = (
176178
'start_date', 'end_date', 'role', 'type', 'country_from', 'country_to',
177179
'deployment', 'molnix_id', 'molnix_tags', 'is_active', 'id',
180+
'surge_alert_id',
178181
'name', 'molnix_status', # 2 plus
179182
)
180183

181184

185+
# Don't forget to adapt drf_views::get_renderer_context if you change this:
182186
class PersonnelCsvSerializerBase(ModelSerializer):
183187
country_from = NanoCountrySerializer()
184188
country_to = NanoCountrySerializer()
@@ -194,6 +198,7 @@ class PersonnelCsvSerializerBase(ModelSerializer):
194198
inactive_status = serializers.SerializerMethodField()
195199
start_date = serializers.SerializerMethodField()
196200
end_date = serializers.SerializerMethodField()
201+
surge_alert_id = serializers.SerializerMethodField()
197202

198203
@staticmethod
199204
def get_start_date(obj):
@@ -242,6 +247,10 @@ def get_ongoing(obj):
242247
end = obj.end_date if obj.end_date else today
243248
return start <= today <= end
244249

250+
@staticmethod
251+
def get_surge_alert_id(obj):
252+
return obj.surge_alert_id
253+
245254

246255
# 3 versions: a "regular", an Anon(yme) and a Super(user) class:
247256
class PersonnelCsvSerializer(PersonnelCsvSerializerBase):
@@ -256,6 +265,7 @@ class Meta:
256265
'deployment', 'id', 'is_active', 'molnix_sector', 'molnix_id',
257266
'molnix_role_profile', 'molnix_language', 'molnix_region', 'molnix_scope',
258267
'molnix_modality', 'molnix_operation', 'ongoing', 'inactive_status',
268+
'surge_alert_id',
259269
)
260270

261271

@@ -270,6 +280,7 @@ class Meta:
270280
'deployment', 'id', 'is_active', 'molnix_sector', 'molnix_id',
271281
'molnix_role_profile', 'molnix_language', 'molnix_region', 'molnix_scope',
272282
'molnix_modality', 'molnix_operation', 'ongoing', 'inactive_status',
283+
'surge_alert_id',
273284
)
274285

275286

@@ -286,6 +297,7 @@ class Meta:
286297
'molnix_status', # plus
287298
'molnix_role_profile', 'molnix_language', 'molnix_region', 'molnix_scope',
288299
'molnix_modality', 'molnix_operation', 'ongoing', 'inactive_status',
300+
'surge_alert_id',
289301
)
290302

291303

deployments/snapshots/snap_tests.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,17 @@
396396
]
397397
}
398398

399-
snapshots['TestProjectAPI::test_personnel_csv_api 1'] = '''event_id,event_glide_id,event_name,event_ifrc_severity_level,event_disaster_type,event_country_name,event_country_iso3,event_country_nationalsociety,event_country_regionname,role,type,name,deployed_id,deployed_to_name,deployed_to_iso3,deployed_to_nationalsociety,deployed_to_regionname,deployed_from_name,deployed_from_iso3,deployed_from_nationalsociety,deployed_from_regionname,start_date,end_date,ongoing,is_active,molnix_id,molnix_sector,molnix_role_profile,molnix_language,molnix_region,molnix_scope,molnix_modality,molnix_operation\r
400-
,,,,,,,,,,,,1,,,,,,,,,,,True,True,,,,,,,,\r
401-
,,,,,,,,,,,,2,,,,,,,,,,,True,True,,,,,,,,\r
402-
,,,,,,,,,,,,3,,,,,,,,,,,True,True,,,,,,,,\r
403-
,,,,,,,,,,,,4,,,,,,,,,,,True,True,,,,,,,,\r
404-
,,,,,,,,,,,,5,,,,,,,,,,,True,True,,,,,,,,\r
405-
,,,,,,,,,,,,6,,,,,,,,,,,True,True,,,,,,,,\r
406-
,,,,,,,,,,,,7,,,,,,,,,,,True,True,,,,,,,,\r
407-
,,,,,,,,,,,,8,,,,,,,,,,,True,True,,,,,,,,\r
408-
,,,,,,,,,,,,9,,,,,,,,,,,True,True,,,,,,,,\r
409-
,,,,,,,,,,,,10,,,,,,,,,,,True,True,,,,,,,,\r
399+
snapshots['TestProjectAPI::test_personnel_csv_api 1'] = '''event_id,event_glide_id,event_name,event_ifrc_severity_level,event_disaster_type,event_country_name,event_country_iso3,event_country_nationalsociety,event_country_regionname,role,type,surge_alert_id,name,deployed_id,deployed_to_name,deployed_to_iso3,deployed_to_nationalsociety,deployed_to_regionname,deployed_from_name,deployed_from_iso3,deployed_from_nationalsociety,deployed_from_regionname,start_date,end_date,ongoing,is_active,molnix_id,molnix_sector,molnix_role_profile,molnix_language,molnix_region,molnix_scope,molnix_modality,molnix_operation\r
400+
,,,,,,,,,,,,,1,,,,,,,,,,,True,True,,,,,,,,\r
401+
,,,,,,,,,,,,,2,,,,,,,,,,,True,True,,,,,,,,\r
402+
,,,,,,,,,,,,,3,,,,,,,,,,,True,True,,,,,,,,\r
403+
,,,,,,,,,,,,,4,,,,,,,,,,,True,True,,,,,,,,\r
404+
,,,,,,,,,,,,,5,,,,,,,,,,,True,True,,,,,,,,\r
405+
,,,,,,,,,,,,,6,,,,,,,,,,,True,True,,,,,,,,\r
406+
,,,,,,,,,,,,,7,,,,,,,,,,,True,True,,,,,,,,\r
407+
,,,,,,,,,,,,,8,,,,,,,,,,,True,True,,,,,,,,\r
408+
,,,,,,,,,,,,,9,,,,,,,,,,,True,True,,,,,,,,\r
409+
,,,,,,,,,,,,,10,,,,,,,,,,,True,True,,,,,,,,\r
410410
'''
411411

412412
snapshots['TestProjectAPI::test_project_create 1'] = {

0 commit comments

Comments
 (0)