55from django .conf import settings
66from api .molnix_utils import MolnixApi
77from api .logger import logger
8- from deployments .models import MolnixTag , PersonnelDeployment , Personnel
8+ from deployments .models import MolnixTag , MolnixTagGroup , PersonnelDeployment , Personnel
99from notifications .models import SurgeAlert , SurgeAlertType , SurgeAlertCategory
1010from api .models import Event , Country , CronJobStatus
1111from api .create_cron import create_cron_record
3030 'ICRC' : 'ICRC'
3131}
3232
33+
3334def get_unique_tags (deployments , open_positions ):
3435 tags = []
3536 tag_ids = []
@@ -41,7 +42,7 @@ def get_unique_tags(deployments, open_positions):
4142 return tags
4243
4344
44- def add_tags (molnix_tags ):
45+ def add_tags (molnix_tags , api ):
4546 modality = ['In Person' , 'Remote' ]
4647 region = ['ASIAP' , 'AMER' , 'AFRICA' , 'MENA' , 'EURO' ]
4748 scope = ['REGIONAL' , 'GLOBAL' ]
@@ -52,6 +53,16 @@ def add_tags(molnix_tags):
5253
5354 for molnix_tag in molnix_tags :
5455 tag , created = MolnixTag .objects .get_or_create (molnix_id = molnix_tag ['id' ])
56+ tag_groups = api .get_tag_groups (molnix_tag ['id' ]) if molnix_tag ['id' ] else []
57+ for g in tag_groups :
58+ tag_group , created = MolnixTagGroup .objects .get_or_create (
59+ molnix_id = g ['id' ],
60+ name = g ['name' ])
61+ if created :
62+ tag_group .created_at = g ['created_at' ]
63+ tag_group .updated_at = g ['updated_at' ]
64+ tag_group .save ()
65+ tag .groups .add (tag_group )
5566 tag .molnix_id = molnix_tag ['id' ]
5667 tag .name = n = molnix_tag ['name' ]
5768 tag .description = molnix_tag ['description' ]
@@ -388,7 +399,7 @@ def handle(self, *args, **options):
388399
389400 try :
390401 used_tags = get_unique_tags (deployments , open_positions )
391- add_tags (used_tags )
402+ add_tags (used_tags , molnix ) # FIXME 2nd arg: a workaround to be able to get the group details inside.
392403 positions_messages , positions_warnings , positions_created = sync_open_positions (open_positions , molnix , countries )
393404 deployments_messages , deployments_warnings , deployments_created = sync_deployments (deployments , molnix , countries )
394405 except Exception as ex :
0 commit comments