from core.models.orm_calls.location_calls import execute_all_locations from core.errors.logger import logger from pathlib import Path def get_all_locations(): """Use core to fetch all locations with SQL""" location_object = execute_all_locations() if not location_object.valid: critical_error = f"Got invalid SQL Query which could not be solved by the wrapper, with error message {location_object.message} and type {location_object.error_type}" logger.error(critical_error) return None list_of_all_locations = location_object.data return list_of_all_locations def get_location_display_data(button_path: str) -> dict|None: """Organize display data for the UI""" all_locations = get_all_locations() if all_locations is None: return None location_display_dto = {} for each_location in all_locations: location_id = each_location.id location_name = each_location.country_name country_code = each_location.country_code provider = each_location.operator.name code = each_location.code button_image_path = f"button_{country_code}_{code}.png" full_image_path = Path(button_path, button_image_path) default_path = Path(button_path, "default_location_button.png") data = { 'path': default_path, 'name': location_name, 'second_line': provider, 'existing_icon': full_image_path } location_display_dto[location_id] = data return location_display_dto