diff --git a/data/spot.py b/data/spot.py index 8af0d15..56f2e78 100644 --- a/data/spot.py +++ b/data/spot.py @@ -133,6 +133,17 @@ class Spot: # The ID the source gave it, if any. source_id: str | None = None + def __post_init__(self): + """Normalise fields that don't survive a plain dict to Spot conversion. This is used in the "add spot" API + endpoint where the client is submitting JSON, and we want to recreate a full Spot object, including nested + objects such as the sig_refs list..""" + + if self.sig_refs: + self.sig_refs = [ + sig_ref if isinstance(sig_ref, SIGRef) else SIGRef(**sig_ref) + for sig_ref in self.sig_refs + ] + def infer_missing(self, credentials=None): """Infer missing parameters where possible""" diff --git a/server/handlers/api/addspot.py b/server/handlers/api/addspot.py index f9eccd1..60c8762 100644 --- a/server/handlers/api/addspot.py +++ b/server/handlers/api/addspot.py @@ -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) diff --git a/templates/add_spot.html b/templates/add_spot.html index f44407c..48eddee 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -76,7 +76,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index cde601a..b38c198 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -75,7 +75,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index c3a1419..59614a9 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -75,8 +75,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index 6c94a47..ee72525 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -10,10 +10,10 @@ - - - - + + + + {% end %} {% block body %}
diff --git a/templates/conditions.html b/templates/conditions.html index 1811421..aa7e3b5 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -284,7 +284,7 @@
- + diff --git a/templates/map.html b/templates/map.html index d4a9efe..47eb5a2 100644 --- a/templates/map.html +++ b/templates/map.html @@ -95,8 +95,8 @@ - - + + diff --git a/templates/spots.html b/templates/spots.html index efd41b4..3e34b08 100644 --- a/templates/spots.html +++ b/templates/spots.html @@ -116,8 +116,8 @@ - - + + diff --git a/templates/status.html b/templates/status.html index 193dc93..e40d244 100644 --- a/templates/status.html +++ b/templates/status.html @@ -59,7 +59,7 @@ - +