Make random page show polygon on map
This commit is contained in:
parent
ea2f172388
commit
690d3281df
32
lookup.py
32
lookup.py
|
@ -188,16 +188,10 @@ def index() -> str | Response:
|
||||||
|
|
||||||
|
|
||||||
@app.route("/random")
|
@app.route("/random")
|
||||||
def random_location() -> str:
|
def random_location() -> str | Response:
|
||||||
"""Return detail page for random lat/lon."""
|
"""Return detail page for random lat/lon."""
|
||||||
lat, lon = get_random_lat_lon()
|
lat, lon = get_random_lat_lon()
|
||||||
|
return build_detail_page(lat, lon)
|
||||||
elements = model.Polygon.coords_within(lat, lon)
|
|
||||||
result = do_lookup(elements, lat, lon)
|
|
||||||
|
|
||||||
return render_template(
|
|
||||||
"detail.html", lat=lat, lon=lon, result=result, elements=elements
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/wikidata_tag")
|
@app.route("/wikidata_tag")
|
||||||
|
@ -223,14 +217,8 @@ def wikidata_tag() -> str:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/detail")
|
def build_detail_page(lat: float, lon: float) -> str:
|
||||||
def detail_page() -> Response | str:
|
"""Run lookup and build detail page."""
|
||||||
"""Detail page."""
|
|
||||||
try:
|
|
||||||
lat_str, lon_str = request.args["lat"], request.args["lon"]
|
|
||||||
lat, lon = float(lat_str), float(lon_str)
|
|
||||||
except TypeError:
|
|
||||||
return redirect(url_for("index"))
|
|
||||||
try:
|
try:
|
||||||
reply = lat_lon_to_wikidata(lat, lon)
|
reply = lat_lon_to_wikidata(lat, lon)
|
||||||
except wikidata.QueryError as e:
|
except wikidata.QueryError as e:
|
||||||
|
@ -251,5 +239,17 @@ def detail_page() -> Response | str:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/detail")
|
||||||
|
def detail_page() -> Response | str:
|
||||||
|
"""Detail page."""
|
||||||
|
try:
|
||||||
|
lat_str, lon_str = request.args["lat"], request.args["lon"]
|
||||||
|
lat, lon = float(lat_str), float(lon_str)
|
||||||
|
except TypeError:
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
return build_detail_page(lat, lon)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0")
|
app.run(host="0.0.0.0")
|
||||||
|
|
Loading…
Reference in a new issue