mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Spotting tweaks. Closes #2
This commit is contained in:
@@ -8,7 +8,7 @@ import bottle
|
||||
import pytz
|
||||
from bottle import run, response, template
|
||||
|
||||
from core.config import MAX_SPOT_AGE
|
||||
from core.config import MAX_SPOT_AGE, ALLOW_SPOTTING
|
||||
from core.constants import BANDS, ALL_MODES, MODE_TYPES, SIGS, CONTINENTS
|
||||
from core.utils import serialize_everything
|
||||
from data.spot import Spot
|
||||
@@ -64,6 +64,12 @@ class WebServer:
|
||||
self.status = "OK"
|
||||
|
||||
try:
|
||||
# Reject if not allowed
|
||||
if not ALLOW_SPOTTING:
|
||||
response.content_type = 'application/json'
|
||||
response.status = 401
|
||||
return json.dumps("Error - this server does not allow new spots to be added via the API.", default=serialize_everything)
|
||||
|
||||
# Reject if no spot
|
||||
if not bottle.request.query.spot:
|
||||
response.content_type = 'application/json'
|
||||
@@ -81,6 +87,8 @@ class WebServer:
|
||||
return json.dumps("Error - 'time' and 'dx_call' must be provided as a minimum.", default=serialize_everything)
|
||||
|
||||
# infer missing data, and add it to our database.
|
||||
spot.source = "API"
|
||||
spot.icon = "desktop"
|
||||
spot.infer_missing()
|
||||
self.spots.add(spot.guid, spot, expire=MAX_SPOT_AGE)
|
||||
|
||||
@@ -91,7 +99,7 @@ class WebServer:
|
||||
logging.error(e)
|
||||
response.content_type = 'application/json'
|
||||
response.status = 422
|
||||
return json.dumps("An error occurred parsing your spot: " + str(e), default=serialize_everything)
|
||||
return json.dumps("Error - " + str(e), default=serialize_everything)
|
||||
|
||||
# Serve a templated page
|
||||
def serve_template(self, template_name):
|
||||
|
||||
Reference in New Issue
Block a user