def commtrack_settings_sync(project): locations_types = ["MOHSW", "REGION", "DISTRICT", "FACILITY"] config = CommtrackConfig.for_domain(project) config.location_types = [] for i, value in enumerate(locations_types): if not any(lt.name == value for lt in config.location_types): allowed_parents = [locations_types[i - 1]] if i > 0 else [""] config.location_types.append( LocationType(name=value, allowed_parents=allowed_parents, administrative=(value != 'FACILITY'))) actions = [action.keyword for action in config.actions] if 'delivered' not in actions: config.actions.append( CommtrackActionConfig( action='receipts', keyword='delivered', caption='Delivered') ) config.save()
def mk_loctype(loctype): loctype['allowed_parents'] = [ p or '' for p in loctype['allowed_parents'] ] return LocationType(**loctype)