58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
# kappa123/server/main/views.py
|
|
|
|
|
|
#################
|
|
#### imports ####
|
|
#################
|
|
|
|
import botocore.session
|
|
from flask import render_template, Blueprint, request, redirect
|
|
from kappa123.server.intpack import pack_ints, unpack_ints
|
|
from kappa123.server.runs import inject_run_class, fetch_or_cache_runs
|
|
|
|
|
|
################
|
|
#### config ####
|
|
################
|
|
|
|
main_blueprint = Blueprint('main', __name__,)
|
|
|
|
|
|
################
|
|
#### routes ####
|
|
################
|
|
|
|
|
|
@main_blueprint.route('/')
|
|
def home():
|
|
all_runs = fetch_or_cache_runs()
|
|
return render_template(
|
|
'main/home.html',
|
|
runs=all_runs
|
|
)
|
|
|
|
|
|
@main_blueprint.route("/about/")
|
|
def about():
|
|
return render_template("main/about.html")
|
|
|
|
@main_blueprint.route("/<preferences>")
|
|
def returning_user(preferences):
|
|
unpacked_set = unpack_ints(preferences)
|
|
all_runs = fetch_or_cache_runs()
|
|
runs = inject_run_class(all_runs, unpacked_set)
|
|
return render_template(
|
|
"main/home.html",
|
|
runs=runs
|
|
)
|
|
|
|
@main_blueprint.route("/code")
|
|
def agplv3_compliance():
|
|
context = request.environ.get('lambda.context')
|
|
session = botocore.session.get_session()
|
|
# region name is detected from lambda environment
|
|
client = session.create_client('lambda')
|
|
code = client.get_function(FunctionName=context.function_name,
|
|
Qualifier=context.function_version)
|
|
return redirect(code['Code']['Location'], code=303)
|