Make stats DSL primary with highlighted editor, completion and live diagnostics
This commit is contained in:
+18
-1
@@ -29,7 +29,7 @@ from .extensions import db, limiter
|
||||
from .history import activity_page, latest_mapped_run, overview, records_for
|
||||
from .models import Activity, Friendship, GarminConnection, User
|
||||
from .services import activity_data, import_cache, import_upload, route_data
|
||||
from .stats import DEFAULT, METRICS, explore, parse_query, query_text
|
||||
from .stats import DEFAULT, METRICS, explore, parse_query, period_bounds, query_text
|
||||
|
||||
web = Blueprint("web", __name__)
|
||||
DUMMY_HASH = generate_password_hash("not-a-real-account-password")
|
||||
@@ -242,6 +242,23 @@ def stats_runs():
|
||||
)
|
||||
|
||||
|
||||
@web.post("/stats/validate")
|
||||
@login_required
|
||||
@limiter.limit("120 per minute")
|
||||
def stats_validate():
|
||||
payload = request.get_json(silent=True)
|
||||
if not isinstance(payload, dict) or not isinstance(payload.get("query"), str):
|
||||
return jsonify(valid=False, diagnostics=[{"line": 1, "message": "Supply query text."}]), 400
|
||||
try:
|
||||
query = parse_query({"query": payload["query"]})
|
||||
period_bounds(query, current_user.timezone)
|
||||
return jsonify(valid=True, canonical=query_text(query), diagnostics=[])
|
||||
except (ValueError, OverflowError) as exc:
|
||||
return jsonify(
|
||||
valid=False, diagnostics=[{"line": getattr(exc, "line", 1), "message": str(exc)}]
|
||||
)
|
||||
|
||||
|
||||
@web.route("/friends", methods=["GET", "POST"])
|
||||
@login_required
|
||||
@limiter.limit("20 per hour", methods=["POST"])
|
||||
|
||||
Reference in New Issue
Block a user