@@ -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