From 75d11d60454a9c2be8ff9c451562a59ded905288 Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 18 Nov 2020 03:05:38 +0000 Subject: [PATCH] Error message template --- db.py | 1 + main.py | 24 ++++++++++++++++++------ templates/message.html | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 templates/message.html diff --git a/db.py b/db.py index 3742e80..0650173 100644 --- a/db.py +++ b/db.py @@ -6,6 +6,7 @@ adb = db.accounts live_quotes_count = lambda: qdb.find({ "hidden": False, "approved": True }) quote_live = lambda quote_id: bool(qdb.find_one({ "hidden": False, "approved": True })) +tag_live = lambda tag: bool(qdb.find_one({ "hidden": False, "approved": True, "tags": tag })) def get_random_quote(): diff --git a/main.py b/main.py index 8f1ce6d..9721c50 100644 --- a/main.py +++ b/main.py @@ -64,12 +64,24 @@ def tags(): @app.route('/tags/') def tag(t): - return render_template( - "list.html", - title=t, - header="Quotes matching: " + t, - quotes=db.get_live_quotes_by_tag(t) - ) + if db.tag_live(t): + return render_template( + "list.html", + title=t, + header="Quotes matching: " + t, + quotes=db.get_live_quotes_by_tag(t) + ) + else: + return render_template( + "message.html", + title="Error!", + message={ + "type": "danger", + "heading": "No matching quotes", + "message": f"There are no quotes with the tag \"{t}\" in the database" + } + ) + @app.route('/quote/') def quote(quote_id): diff --git a/templates/message.html b/templates/message.html new file mode 100644 index 0000000..f70476a --- /dev/null +++ b/templates/message.html @@ -0,0 +1,14 @@ +{% extends "layout.html" %} +{% block customhead %} + {{ title }} +{% endblock %} +{% block content %} + +
+ +
+ +{% endblock %}