Coverage for netbox/ui/utils.py: 27%

9 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1__all__ = ( 

2 'build_coords_url', 

3 'is_coordinate_map_url', 

4) 

5 

6 

7def is_coordinate_map_url(url): 

8 """Return True if the URL contains GPS coordinate placeholders ({lat} or {lon}).""" 

9 return '{lat}' in url or '{lon}' in url 

10 

11 

12def build_coords_url(map_url, latitude, longitude): 

13 """ 

14 Build a GPS map URL from a base URL and coordinate values. 

15 

16 If the URL contains {lat} or {lon} placeholders they are substituted directly; 

17 otherwise the coordinates are appended as a comma-separated pair. 

18 """ 

19 lat_str = str(latitude) 

20 lon_str = str(longitude) 

21 if is_coordinate_map_url(map_url): 

22 return map_url.replace('{lat}', lat_str).replace('{lon}', lon_str) 

23 return f'{map_url}{lat_str},{lon_str}'