mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 22:37:44 +00:00
Giant refactor to rebrand "SIG" as "Activity" anywhere that doesn't touch API or config file (which is to be addressed in a future breaking change). #147
This commit is contained in:
@@ -6,18 +6,18 @@ import tornado
|
||||
from tornado import httputil
|
||||
from tornado.web import Application
|
||||
|
||||
from core.activity_lookup_helper import populate_missing_activity_ref_info
|
||||
from core.activity_utils import get_ref_regex_for_activity
|
||||
from core.call_lookup_helper import get_call_info
|
||||
from core.constants import SIGS
|
||||
from core.constants import ACTIVITIES
|
||||
from core.geo_utils import (
|
||||
lat_lon_for_grid_sw_corner_plus_size,
|
||||
lat_lon_to_cq_zone,
|
||||
lat_lon_to_itu_zone,
|
||||
)
|
||||
from core.sig_lookup_helper import populate_missing_sig_ref_info
|
||||
from core.sig_utils import get_ref_regex_for_sig
|
||||
from core.utils import safe_json_dumps
|
||||
from data.activity_ref import ActivityRef
|
||||
from data.lookup_credentials import extract_credentials
|
||||
from data.sig_ref import SIGRef
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -63,7 +63,7 @@ class APILookupCallHandler(tornado.web.RequestHandler):
|
||||
self.set_header("Content-Type", "application/json")
|
||||
|
||||
|
||||
class APILookupSIGRefHandler(tornado.web.RequestHandler):
|
||||
class APILookupActivityRefHandler(tornado.web.RequestHandler):
|
||||
"""API request handler for /api/v2/lookup/sigref"""
|
||||
|
||||
def __init__(
|
||||
@@ -80,30 +80,34 @@ class APILookupSIGRefHandler(tornado.web.RequestHandler):
|
||||
# reduce that to just the first entry, and convert bytes to string
|
||||
query_params = {k: v[0].decode("utf-8") for k, v in self.request.arguments.items()}
|
||||
|
||||
# "sig" and "id" query params must exist, SIG must be known, and if we have a reference regex for that SIG,
|
||||
# the provided id must match it.
|
||||
# "sig" and "id" query params must exist, the activity must be known, and if we have a reference regex for
|
||||
# that activity, the provided id must match it.
|
||||
if "sig" in query_params and "id" in query_params:
|
||||
sig = str(query_params.get("sig")).upper()
|
||||
activity = str(query_params.get("sig")).upper()
|
||||
ref_id = str(query_params.get("id")).upper()
|
||||
if sig in [p.name.upper() for p in SIGS]:
|
||||
if not get_ref_regex_for_sig(sig) or re.match(get_ref_regex_for_sig(sig), ref_id):
|
||||
data = populate_missing_sig_ref_info(SIGRef(id=ref_id, sig=sig))
|
||||
if activity in [a.name.upper() for a in ACTIVITIES]:
|
||||
if not get_ref_regex_for_activity(activity) or re.match(
|
||||
get_ref_regex_for_activity(activity), ref_id
|
||||
):
|
||||
data = populate_missing_activity_ref_info(ActivityRef(id=ref_id, sig=activity))
|
||||
self.write(safe_json_dumps(data))
|
||||
|
||||
else:
|
||||
self.write(
|
||||
safe_json_dumps(f"Error - '{ref_id}' does not look like a valid reference ID for {sig}.")
|
||||
safe_json_dumps(
|
||||
f"Error - '{ref_id}' does not look like a valid reference ID for {activity}."
|
||||
)
|
||||
)
|
||||
self.set_status(422)
|
||||
else:
|
||||
self.write(safe_json_dumps(f"Error - sig '{sig}' is not known."))
|
||||
self.write(safe_json_dumps(f"Error - sig '{activity}' is not known."))
|
||||
self.set_status(422)
|
||||
else:
|
||||
self.write(safe_json_dumps("Error - sig and id must be provided"))
|
||||
self.set_status(422)
|
||||
|
||||
except Exception:
|
||||
logger.exception("Exception when handling client request to sig ref lookup API")
|
||||
logger.exception("Exception when handling client request to activity ref lookup API")
|
||||
self.write(safe_json_dumps("Error - an internal server error occurred."))
|
||||
self.set_status(500)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user