Skip to content

Commit 2108d58

Browse files
committed
DBC22-6929: deleted local weather link if code does not exist in ccp
1 parent 85fc9f4 commit 2108d58

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/backend/apps/webcam/tasks.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,18 @@ def format_region_name(region_name):
147147

148148
def update_current_weather_code(cam_id: int, cam_data: dict):
149149
cam = Webcam.objects.get(id=cam_id)
150-
local_weather_station_id = cam.local_weather_station_id
151-
code = cam_data.get("cam_locations_weather_station")
152-
update_data = {
153-
"code": code,
154-
}
155-
CurrentWeather.objects.filter(id=local_weather_station_id).update(**update_data)
150+
code = cam_data.get("cam_locations_weather_station", "").strip()
151+
152+
# Remove the link if there is no weather station code
153+
if not code:
154+
cam.local_weather_station = None
155+
cam.save(update_fields=["local_weather_station_id"])
156+
157+
# Update the linked CurrentWeather record
158+
CurrentWeather.objects.filter(
159+
id=cam.local_weather_station_id
160+
).update(code=code)
161+
156162
return True
157163

158164
def update_webcam_db(cam_id: int, cam_data: dict):
@@ -559,7 +565,7 @@ def update_camera_weather_station(camera, weather_class):
559565

560566
if weather_class == CurrentWeather:
561567
stations_qs = stations_qs.filter(
562-
distance__lte=D(km=30),
568+
# distance__lte=D(km=30),
563569
elevation__lte=camera.elevation + 300,
564570
elevation__gte=camera.elevation - 300,
565571
)

0 commit comments

Comments
 (0)