EXTRA_STATIC_PATH: basic support for custom pages

This commit is contained in:
boyska 2019-07-05 01:32:01 +02:00
parent d19b18eb3c
commit 4d492def58
2 changed files with 17 additions and 0 deletions

View file

@ -19,6 +19,7 @@ def get_conf(prefix="LARIGIRA_"):
conf["CACHING_TIME"] = 10
conf["DB_URI"] = os.path.join(conf_dir, "db.json")
conf["SCRIPTS_PATH"] = os.path.join(conf_dir, "scripts")
conf["EXTRA_STATIC_PATH"] = os.path.join(conf_dir, "extra")
conf["ROUTE_PREFIX"] = ""
conf["BOOTSTRAP_SERVE_LOCAL"] = True
conf["SECRET_KEY"] = "Please replace me!"

View file

@ -4,12 +4,15 @@ This module contains a flask blueprint for db administration stuff
Templates are self-contained in this directory
"""
from __future__ import print_function
import os
from datetime import datetime, timedelta, time
from collections import defaultdict
import mimetypes
from flask import (
current_app,
Blueprint,
Response,
render_template,
jsonify,
abort,
@ -227,3 +230,16 @@ def delete_alarm(alarmid):
return jsonify(dict(deleted=alarmid))
flash("Evento %d `%s` cancellato" % (alarmid, alarm["nick"]))
return redirect(url_for("db.events_list"))
@db.route("/quick/<path:relpath>")
def static_custom(relpath):
basepath = get_conf()['EXTRA_STATIC_PATH']
if not basepath:
abort(405)
fpath = os.path.join(basepath, relpath)
print(basepath, fpath)
if not os.path.isfile(fpath):
abort(404, "File non trovato")
mime, _encoding = mimetypes.guess_type(fpath)
return Response(open(fpath, 'rb').read(), mimetype=mime)