mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-25 08:44:33 +00:00
Strict adherence to canonical ActivityNames, to avoid the problem where Spothole was giving out activities like ["Towers", "TOWERS"]. All uses of ActivityName should now be canonical not arbitrary strings, and attempts to convert unknown strings to activitynames will be logged for me to check out.
This commit is contained in:
@@ -7,7 +7,7 @@ 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_activity_by_name, get_ref_regex_for_activity
|
||||
from core.activity_utils import get_activity_by_name
|
||||
from core.call_lookup_helper import get_call_info
|
||||
from core.geo_utils import (
|
||||
lat_lon_for_grid_sw_corner_plus_size,
|
||||
@@ -82,12 +82,11 @@ class APILookupActivityRefHandler(tornado.web.RequestHandler):
|
||||
# "activity" 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 "activity" in query_params and "id" in query_params:
|
||||
activity = str(query_params.get("activity")).upper()
|
||||
found_activity = get_activity_by_name(str(query_params.get("activity")))
|
||||
ref_id = str(query_params.get("id")).upper()
|
||||
if get_activity_by_name(activity):
|
||||
if not get_ref_regex_for_activity(activity) or re.match(
|
||||
get_ref_regex_for_activity(activity), ref_id
|
||||
):
|
||||
if found_activity is not None:
|
||||
activity = found_activity.name
|
||||
if not found_activity.ref_regex or re.match(found_activity.ref_regex, ref_id):
|
||||
data = populate_missing_activity_ref_info(ActivityRef(id=ref_id, activity=activity))
|
||||
self.write(safe_json_dumps(data))
|
||||
|
||||
@@ -99,7 +98,7 @@ class APILookupActivityRefHandler(tornado.web.RequestHandler):
|
||||
)
|
||||
self.set_status(422)
|
||||
else:
|
||||
self.write(safe_json_dumps(f"Error - activity '{activity}' is not known."))
|
||||
self.write(safe_json_dumps(f"Error - activity '{query_params.get('activity')}' is not known."))
|
||||
self.set_status(422)
|
||||
else:
|
||||
self.write(safe_json_dumps("Error - activity and id must be provided"))
|
||||
|
||||
Reference in New Issue
Block a user