From 20c3432e6d15d288007c9553b2e43df358d01caf Mon Sep 17 00:00:00 2001 From: Kate Date: Sun, 15 Nov 2020 22:11:33 +0000 Subject: [PATCH] Individual quote pages --- db.py | 7 +++++++ main.py | 8 ++++++++ templates/latest.html | 7 ++++--- templates/quote.html | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 templates/quote.html diff --git a/db.py b/db.py index 5ac45d2..da53650 100644 --- a/db.py +++ b/db.py @@ -5,6 +5,7 @@ qdb = db.quotes 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 })) def get_random_quote(): @@ -16,6 +17,12 @@ def get_random_quote(): return(x if x else False) +def get_quote_by_id(quote_id): + if quote_live(quote_id): + return qdb.find_one({ "id": quote_id }) + else: + return False + def add_quote(quote, tags, author): qdb.insert_one({ "id": nanoid.generate(size=12), diff --git a/main.py b/main.py index 9b05e3a..7d2cc68 100644 --- a/main.py +++ b/main.py @@ -61,5 +61,13 @@ def tags(): tags=db.count_live_quotes_by_tag() ) +@app.route('/quote/') +def quote(quote_id): + return render_template( + "quote.html", + title="Quote " + quote_id, + quote= db.get_quote_by_id(quote_id) + ) + if __name__ == "__main__": app.run(host="0.0.0.0", debug=True) diff --git a/templates/latest.html b/templates/latest.html index 88a0bdc..0287042 100644 --- a/templates/latest.html +++ b/templates/latest.html @@ -5,18 +5,19 @@ {% block nav_latest %}active{% endblock %} {% block content %} -
+

Latest Quotes

{% for quote in quotes %}
-

Quote {{quote.id}}

+

ID:{{quote.id}}

+ + -->
{{ quote.quote }}
diff --git a/templates/quote.html b/templates/quote.html new file mode 100644 index 0000000..4714a64 --- /dev/null +++ b/templates/quote.html @@ -0,0 +1,14 @@ +{% extends "layout.html" %} +{% block customhead %} + {{ title }} +{% endblock %} +{% block content %} + +
+
+        {{ quote.quote }}
+    
+

Tags: {% for tag in quote.tags %}{{tag}}{% if not loop.last %}, {% endif %}{% endfor %}

+
+ +{% endblock %}