Skip to content

Commit d7aae8c

Browse files
Merge pull request #2455 from IFRCGo/feature/changed-NEC-structure
Update Molnix alert status even when no event
2 parents 9818984 + 6a4e662 commit d7aae8c

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

api/management/commands/ingest_ns_initiatives.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def handle(self, *args, **kwargs):
5858
"Categories",
5959
"AllocationInCHF",
6060
"FundingPeriodInMonths",
61+
"FundingType",
62+
"FundingPeriodInYears",
6163
],
6264
)
6365
funding_data = funding_data.replace({np.nan: None})
@@ -69,12 +71,12 @@ def handle(self, *args, **kwargs):
6971
nsd_initiatives, created = NSDInitiatives.objects.get_or_create(
7072
country=country,
7173
year=data[1],
72-
fund_type=data[2],
74+
fund_type=f"{data[2]} ({data[7]})" if data[7] else data[2],
7375
defaults={
7476
"title": data[3],
7577
"categories": data[4],
7678
"allocation": data[5],
77-
"funding_period": data[6],
79+
"funding_period": data[6] if data[6] else data[8] * 12,
7880
},
7981
)
8082
if not created:

api/management/commands/sync_molnix.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def sync_deployments(molnix_deployments, molnix_api, countries):
292292
p.save()
293293

294294
# Create Personnel objects
295-
for md in molnix_deployments:
295+
for md in molnix_deployments: # LOOP1
296296
if "position_id" not in md: # changed structure §
297297
md2 = molnix_api.get_deployment(md["id"])
298298
md |= md2["deployment"]
@@ -465,7 +465,7 @@ def sync_open_positions(molnix_positions, molnix_api, countries):
465465
successful_creates = 0
466466
successful_updates = 0
467467

468-
for position in molnix_positions:
468+
for position in molnix_positions: # LOOP2
469469
logger.warning("× " + str(position["id"]))
470470
if skip_this(position["tags"]):
471471
warning = "Position id %d skipped due to No-GO" % position["id"]
@@ -479,22 +479,26 @@ def sync_open_positions(molnix_positions, molnix_api, countries):
479479
logger.warning(warning)
480480
warnings.append(warning)
481481
# Do not skip these countryless positions, remove "continue" from code.
482-
# If no valid GO Emergency tag is found, skip Position
483-
if not event:
484-
warning = "Position id %d does not have a valid Emergency tag." % position["id"]
485-
prt("Position does not have a valid Emergency tag", 0, position["id"])
486-
logger.warning(warning)
487-
warnings.append(warning)
488-
continue
489482
go_alert, created = SurgeAlert.objects.get_or_create(molnix_id=position["id"])
483+
event = get_go_event(position["tags"])
484+
if event:
485+
go_alert.event = event
486+
# When no Emergency (= event) found, we do not overwrite the previously (maybe) existing one
487+
else:
488+
if created:
489+
# If no valid GO Emergency tag is found, skip Position – in case of a NEW Position.
490+
warning = "Position id %d does not have a valid Emergency tag." % position["id"]
491+
prt("Position does not have a valid Emergency tag", 0, position["id"])
492+
logger.warning(warning)
493+
warnings.append(warning)
494+
continue
490495
# We set all Alerts coming from Molnix to RR / Alert
491496
go_alert.atype = SurgeAlertType.RAPID_RESPONSE
492497
go_alert.category = SurgeAlertCategory.ALERT
493498
# print(json.dumps(position, indent=2))
494499
go_alert.molnix_id = position["id"]
495500
go_alert.message = position["name"]
496501
go_alert.molnix_status = SurgeAlert.parse_molnix_status(position["status"])
497-
go_alert.event = event
498502
go_alert.country = country
499503
go_alert.opens = get_datetime(position["opens"])
500504
go_alert.closes = get_datetime(position["closes"])

0 commit comments

Comments
 (0)