From b20d7119e4f6506cdb9d5d11322e28130823adfd Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 23 Oct 2017 19:56:27 -0700 Subject: [PATCH] Implemented template inheritance and brought back errors --- app.py | 22 +++++++--------------- templates/base.html | 14 ++++++++++++++ templates/database.html | 6 ++++++ templates/index.html | 7 +++++++ templates/table.html | 6 ++++++ 5 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 templates/base.html diff --git a/app.py b/app.py index c7a85290..cc6e43ad 100644 --- a/app.py +++ b/app.py @@ -86,7 +86,13 @@ class BaseView(HTTPMethodView): as_json = kwargs.pop('as_json') except KeyError: as_json = False - data = self.data(request, name, hash, **kwargs) + try: + data = self.data(request, name, hash, **kwargs) + except sqlite3.OperationalError as e: + data = { + 'ok': False, + 'error': str(e), + } if as_json: r = response.json(data) r.headers['Access-Control-Allow-Origin'] = '*' @@ -103,21 +109,7 @@ class BaseView(HTTPMethodView): return r -def sqlerrors(fn): - @wraps(fn) - async def inner(*args, **kwargs): - try: - return await fn(*args, **kwargs) - except sqlite3.OperationalError as e: - return response.json({ - 'ok': False, - 'error': str(e), - }) - return inner - - @app.route('/') -@sqlerrors async def index(request, sql=None): databases = ensure_build_metadata(True) return jinja.render( diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 00000000..6525c6eb --- /dev/null +++ b/templates/base.html @@ -0,0 +1,14 @@ + + + + {% block title %}{% endblock %} +{% block extra_head %}{% endblock %} + + +{% if error %} +
{{ error }}
+{% endif %} +{% block content %} +{% endblock %} + + diff --git a/templates/database.html b/templates/database.html index f5d36cf8..f8e62230 100644 --- a/templates/database.html +++ b/templates/database.html @@ -1,3 +1,8 @@ +{% extends "base.html" %} + +{% block title %}{{ database }}{% endblock %} + +{% block content %}

{{ database }}