haldis/app/views/debug.py

34 lines
839 B
Python
Raw Normal View History

2019-09-10 00:50:22 +00:00
"View used for debugging Haldis"
from flask import Blueprint
from flask import current_app as app
from flask import url_for
from flask_login import login_required
2019-09-05 01:33:29 +00:00
debug_bp = Blueprint("debug_bp", __name__)
2019-09-05 01:33:29 +00:00
@debug_bp.route("/routes")
@login_required
2019-09-07 23:34:16 +00:00
def list_routes() -> str:
2019-09-10 00:50:22 +00:00
"List all routes of the application"
import urllib
2019-09-05 01:33:29 +00:00
output = []
for rule in app.url_map.iter_rules():
options = {}
for arg in rule.arguments:
2022-04-19 20:03:00 +00:00
options[arg] = f"[{arg}]"
print(rule.endpoint)
2019-09-05 01:33:29 +00:00
methods = ",".join(rule.methods)
url = url_for(rule.endpoint, **options)
2019-09-05 01:33:29 +00:00
line = urllib.parse.unquote(
2022-04-19 20:03:00 +00:00
f"{rule.endpoint:50s} {methods:20s} {url}"
2019-09-05 01:33:29 +00:00
)
output.append(line)
2019-09-05 01:33:29 +00:00
string = ""
for line in sorted(output):
string += line + "<br/>"
return string