hydraveil-gui/gui/v2/actions/locations.py
2026-06-13 16:19:11 -04:00

34 lines
897 B
Python
Executable file

def location_candidates(profile, preferred=None):
candidates = []
seen = set()
def add(val):
if val is None:
return
s = str(val).strip().lower().replace(' ', '_')
if s and s not in seen:
seen.add(s)
candidates.append(s)
if preferred:
add(preferred)
sources = []
try:
if profile and profile.connection and profile.connection.location:
sources.append(profile.connection.location)
except Exception:
pass
try:
if profile and profile.location:
sources.append(profile.location)
except Exception:
pass
for source in sources:
add(getattr(source, 'country_name', None))
add(getattr(source, 'name', None))
add(getattr(source, 'code', None))
add(getattr(source, 'country_code', None))
return candidates