From e660627249b5714d7b288ab7debdaa6fa4a157cb Mon Sep 17 00:00:00 2001 From: mcbloch Date: Wed, 4 Sep 2019 17:18:11 +0200 Subject: [PATCH] move routes endpoint to debug blueprint --- app/app.py | 4 ++++ app/views/debug.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 app/views/debug.py diff --git a/app/app.py b/app/app.py index e121ce8..0447a24 100644 --- a/app/app.py +++ b/app/app.py @@ -111,6 +111,7 @@ def add_routes(application): from views.order import order_bp from views.general import general_bp from views.stats import stats_blueprint + from views.debug import debug_bp from login import auth_bp from zeus import oauth_bp @@ -120,6 +121,9 @@ def add_routes(application): application.register_blueprint(auth_bp, url_prefix='/') application.register_blueprint(oauth_bp, url_prefix='/') + if application.debug: + application.register_blueprint(debug_bp, url_prefix='/debug') + def add_template_filters(app): @app.template_filter('countdown') diff --git a/app/views/debug.py b/app/views/debug.py new file mode 100644 index 0000000..e0df5ad --- /dev/null +++ b/app/views/debug.py @@ -0,0 +1,29 @@ +from flask import Blueprint +from flask import current_app as app +from flask import url_for +from flask_login import login_required + +debug_bp = Blueprint('debug_bp', __name__) + + +@debug_bp.route('/routes') +@login_required +def list_routes(): + import urllib + output = [] + for rule in app.url_map.iter_rules(): + options = {} + for arg in rule.arguments: + options[arg] = "[{0}]".format(arg) + print(rule.endpoint) + methods = ','.join(rule.methods) + url = url_for(rule.endpoint, **options) + line = urllib.parse.unquote("{:50s} {:20s} {}".format( + rule.endpoint, methods, url)) + output.append(line) + + string = '' + for line in sorted(output): + string += line + "
" + + return string