parent
02b32dd5ef
commit
e6e113e14a
4 changed files with 158 additions and 3 deletions
38
web_view.py
38
web_view.py
|
|
@ -2,16 +2,48 @@
|
|||
|
||||
"""Web page to show upcoming events."""
|
||||
|
||||
import inspect
|
||||
import sys
|
||||
import traceback
|
||||
from datetime import date, datetime, timezone
|
||||
|
||||
from flask import Flask, render_template
|
||||
import flask
|
||||
import werkzeug
|
||||
import werkzeug.debug.tbtools
|
||||
|
||||
from agenda import get_data
|
||||
|
||||
app = Flask(__name__)
|
||||
app = flask.Flask(__name__)
|
||||
app.debug = True
|
||||
|
||||
|
||||
@app.errorhandler(werkzeug.exceptions.InternalServerError)
|
||||
def exception_handler(e: werkzeug.exceptions.InternalServerError) -> tuple[str, int]:
|
||||
"""Handle exception."""
|
||||
exec_type, exc_value, current_traceback = sys.exc_info()
|
||||
assert exc_value
|
||||
tb = werkzeug.debug.tbtools.DebugTraceback(exc_value)
|
||||
|
||||
summary = tb.render_traceback_html(include_title=False)
|
||||
exc_lines = "".join(tb._te.format_exception_only())
|
||||
|
||||
last_frame = list(traceback.walk_tb(current_traceback))[-1][0]
|
||||
last_frame_args = inspect.getargs(last_frame.f_code)
|
||||
|
||||
return (
|
||||
flask.render_template(
|
||||
"show_error.html",
|
||||
plaintext=tb.render_traceback_text(),
|
||||
exception=exc_lines,
|
||||
exception_type=tb._te.exc_type.__name__,
|
||||
summary=summary,
|
||||
last_frame=last_frame,
|
||||
last_frame_args=last_frame_args,
|
||||
),
|
||||
500,
|
||||
)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index() -> str:
|
||||
"""Index page."""
|
||||
|
|
@ -27,7 +59,7 @@ def index() -> str:
|
|||
def days(when: date) -> str:
|
||||
return "today" if when == today else f"{(when - today).days:,d} days"
|
||||
|
||||
return render_template("index.html", days=days, days_hours=days_hours, **data)
|
||||
return flask.render_template("index.html", days=days, days_hours=days_hours, **data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue