Create SIGRef objects when converting dict to Spot object in the spot object's own __post_init__ method rather than in add_spot.py

This commit is contained in:
Ian Renton
2026-07-10 17:45:43 +01:00
parent 600a330e63
commit eee0d70140
10 changed files with 26 additions and 25 deletions
-10
View File
@@ -1,4 +1,3 @@
import json
import logging
import re
from datetime import datetime
@@ -15,7 +14,6 @@ from core.lookup_helper import infer_band_from_freq
from core.prometheus_metrics_handler import api_requests_counter
from core.sig_utils import get_ref_regex_for_sig
from core.utils import safe_json_dumps
from data.sig_ref import SIGRef
from data.spot import Spot
@@ -68,14 +66,6 @@ class APISpotHandler(tornado.web.RequestHandler):
json_spot = tornado.escape.json_decode(post_data)
spot = Spot(**json_spot)
# Converting to a spot object this way won't have coped with sig_ref objects, so fix that. (Would be nice to
# redo this in a functional style)
if spot.sig_refs:
real_sig_refs = []
for dict_obj in spot.sig_refs:
real_sig_refs.append(json.loads(json.dumps(dict_obj), object_hook=lambda d: SIGRef(**d)))
spot.sig_refs = real_sig_refs
# Reject if no timestamp, frequency, dx_call or de_call
if not spot.time or not spot.dx_call or not spot.freq or not spot.de_call:
self.set_status(422)