diff --git a/core/constants.py b/core/constants.py index b4a383e..9a9703e 100644 --- a/core/constants.py +++ b/core/constants.py @@ -24,11 +24,11 @@ SIGS = [ SIG(name="SIOTA", description="Silos on the Air", icon="wheat-awn", ref_regex=r"[A-Z]{2}\-[A-Z]{3}\d"), SIG(name="WCA", description="World Castles Award", icon="chess-rook", ref_regex=r"[A-Z0-9]{1,3}\-\d+"), SIG(name="ZLOTA", description="New Zealand on the Air", icon="kiwi-bird", ref_regex=r"ZL[A-Z]/[A-Z]{2}\-\d+"), + SIG(name="WOTA", description="Wainwrights on the Air", icon="w", ref_regex=r"[A-Z]{3}-[0-9]{2}"), + SIG(name="BOTA", description="Beaches on the Air", icon="water"), SIG(name="KRMNPA", description="Keith Roget Memorial National Parks Award", icon="earth-oceania", ref_regex=r""), SIG(name="WAB", description="Worked All Britain", icon="table-cells-large", ref_regex=r"[A-Z]{1,2}[0-9]{2}"), - SIG(name="WAI", description="Worked All Ireland", icon="table-cells-large", ref_regex=r"[A-Z][0-9]{2}"), - SIG(name="WOTA", description="Wainwrights on the Air", icon="w", ref_regex=r"[A-Z]{3}-[0-9]{2}"), - SIG(name="BOTA", description="Beaches on the Air", icon="water") + SIG(name="WAI", description="Worked All Ireland", icon="table-cells-large", ref_regex=r"[A-Z][0-9]{2}") ] # Modes. Note "DIGI" and "DIGITAL" are also supported but are normalised into "DATA". diff --git a/server/webserver.py b/server/webserver.py index aab70b0..a05dd28 100644 --- a/server/webserver.py +++ b/server/webserver.py @@ -12,6 +12,8 @@ from core.config import MAX_SPOT_AGE, ALLOW_SPOTTING from core.constants import BANDS, ALL_MODES, MODE_TYPES, SIGS, CONTINENTS, SOFTWARE_VERSION, UNKNOWN_BAND from core.lookup_helper import lookup_helper from core.prometheus_metrics_handler import page_requests_counter, get_metrics, api_requests_counter +from core.sig_utils import get_ref_regex_for_sig +from data.sig_ref import SIGRef from data.spot import Spot @@ -140,6 +142,14 @@ class WebServer: json_spot = json.loads(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: response.content_type = 'application/json' @@ -171,6 +181,13 @@ class WebServer: response.status = 422 return json.dumps("Error - '" + spot.dx_grid + "' does not look like a valid Maidenhead grid.", default=serialize_everything) + # Reject if sig_ref format incorrect for sig + print(spot.sig_refs[0]) + if spot.sig and spot.sig_refs and len(spot.sig_refs) > 0 and spot.sig_refs[0].id and get_ref_regex_for_sig(spot.sig) and not re.match(get_ref_regex_for_sig(spot.sig), spot.sig_refs[0].id): + response.content_type = 'application/json' + response.status = 422 + return json.dumps("Error - '" + spot.sig_refs[0].id + "' does not look like a valid reference for " + spot.sig + ".", default=serialize_everything) + # infer missing data, and add it to our database. spot.source = "API" if not spot.sig: diff --git a/views/webpage_add_spot.tpl b/views/webpage_add_spot.tpl index 090ece9..3fa2b45 100644 --- a/views/webpage_add_spot.tpl +++ b/views/webpage_add_spot.tpl @@ -24,21 +24,31 @@
* Required field
diff --git a/webassets/js/add-spot.js b/webassets/js/add-spot.js index 9b1a0e6..21fdf7e 100644 --- a/webassets/js/add-spot.js +++ b/webassets/js/add-spot.js @@ -13,6 +13,14 @@ function loadOptions() { })); }); + // Populate SIG drop-down + $.each(options["sigs"], function (i, sig) { + $('#sig').append($('