Create attractive VASL scenarios, with loads of useful information embedded to assist with game play. https://vasl-templates.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vasl-templates/vasl_templates/webapp/main.py

60 lines
1.6 KiB

""" Main webapp handlers. """
import os
import json
from flask import request, render_template, jsonify, redirect, url_for
from vasl_templates.webapp import app
from vasl_templates.webapp.config.constants import DATA_DIR
# ---------------------------------------------------------------------
@app.route( "/" )
def main():
"""Return the main page."""
return render_template( "index.html" )
# ---------------------------------------------------------------------
@app.route( "/help" )
def show_help():
"""Show the help page."""
url = url_for( "static", filename="help/index.html" )
if request.args.get( "embedded" ):
url += "?embedded=1"
return redirect( url, code=302 )
# ---------------------------------------------------------------------
default_scenario = None
@app.route( "/default-scenario" )
def get_default_scenario():
"""Return the default scenario."""
# check if a default scenario has been configured
if default_scenario:
fname = default_scenario
else:
fname = os.path.join( app.config.get("DATA_DIR",DATA_DIR), "default-scenario.json" )
# return the default scenario
with open(fname,"r") as fp:
return jsonify( json.load( fp ) )
# ---------------------------------------------------------------------
@app.route( "/ping" )
def ping():
"""Let the caller know we're alive."""
return "pong"
# ---------------------------------------------------------------------
@app.route( "/shutdown" )
def shutdown():
"""Shutdown the webapp (for testing porpoises)."""
request.environ.get( "werkzeug.server.shutdown" )()
return ""