First attempt at converting "sig" to "activity" for v3

This commit is contained in:
Ian Renton
2026-09-24 07:09:37 +01:00
parent 1d0129f7bb
commit d91fa70655
90 changed files with 822 additions and 496 deletions
+13 -10
View File
@@ -11,12 +11,14 @@ from core.config import ALLOW_SPOTTING
from core.constants import UNKNOWN_BAND
from core.utils import infer_band_from_freq, safe_json_dumps
from data.spot import Spot
from webserver.handlers.api.v2_compatibility import translate_v2_spot
logger = logging.getLogger(__name__)
class V1APISpotHandler(tornado.web.RequestHandler):
"""API request handler for /api/v1/spot (POST). Included in early Spothole v2 for backwards compatibility."""
"""API request handler for /api/v1/spot (POST). Included in Spothole v2 onwards for backwards
compatibility."""
def __init__(
self,
@@ -57,8 +59,9 @@ class V1APISpotHandler(tornado.web.RequestHandler):
self.set_header("Content-Type", "application/json")
return
# Read in the request body as JSON then convert to a Spot object
json_spot = tornado.escape.json_decode(post_data)
# Read in the request body as JSON then convert to a Spot object. The v1 spot format uses the same field
# names as v2, so needs the same translation to v3 field names.
json_spot = translate_v2_spot(tornado.escape.json_decode(post_data))
spot = Spot(**json_spot)
# Reject if no timestamp, frequency, dx_call or de_call
@@ -106,17 +109,17 @@ class V1APISpotHandler(tornado.web.RequestHandler):
# Reject if activity ref format incorrect for activity
if (
spot.sig
and spot.sig_refs
and len(spot.sig_refs) > 0
and spot.sig_refs[0].id
and get_ref_regex_for_activity(spot.sig)
and not re.match(get_ref_regex_for_activity(spot.sig), spot.sig_refs[0].id)
spot.activity
and spot.activity_refs
and len(spot.activity_refs) > 0
and spot.activity_refs[0].id
and get_ref_regex_for_activity(spot.activity)
and not re.match(get_ref_regex_for_activity(spot.activity), spot.activity_refs[0].id)
):
self.set_status(422)
self.write(
safe_json_dumps(
f"Error - '{spot.sig_refs[0].id}' does not look like a valid reference for {spot.sig}."
f"Error - '{spot.activity_refs[0].id}' does not look like a valid reference for {spot.activity}."
)
)
self.set_header("Cache-Control", "no-store")