From 4d492def58acd957b0ae5e90b0983364a91013a7 Mon Sep 17 00:00:00 2001 From: boyska Date: Fri, 5 Jul 2019 01:32:01 +0200 Subject: [PATCH] EXTRA_STATIC_PATH: basic support for custom pages --- larigira/config.py | 1 + larigira/dbadmin/__init__.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/larigira/config.py b/larigira/config.py index c398570..0a81dfa 100644 --- a/larigira/config.py +++ b/larigira/config.py @@ -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!" diff --git a/larigira/dbadmin/__init__.py b/larigira/dbadmin/__init__.py index 1361235..6ab263b 100644 --- a/larigira/dbadmin/__init__.py +++ b/larigira/dbadmin/__init__.py @@ -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/") +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)