Individual quote pages

This commit is contained in:
Kate 2020-11-15 22:11:33 +00:00
parent 478e9dba1b
commit 20c3432e6d
4 changed files with 33 additions and 3 deletions

7
db.py
View file

@ -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),

View file

@ -61,5 +61,13 @@ def tags():
tags=db.count_live_quotes_by_tag()
)
@app.route('/quote/<quote_id>')
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)

View file

@ -5,18 +5,19 @@
{% block nav_latest %}active{% endblock %}
{% block content %}
<div class = "container">
<div class="container">
<h1 class="display-4 mb-5">Latest Quotes</h1>
{% for quote in quotes %}
<div>
<div class="d-flex justify-content-between">
<p class="h4">Quote {{quote.id}}</p>
<p class="small block"><a href="/quote/{{ quote.id }}">ID:{{quote.id}}</a></p>
<!-- These buttons will be admin tools
<span>
<!-- These buttons will be admin tools -->
<button class="btn btn-link btn-sm"><i class="fas fa-pencil-alt"></i></button>
<button class="btn btn-link text-danger btn-sm"><i class="fas fa-times"></i></button>
</span>
-->
</div>
<pre>{{ quote.quote }}</pre>

14
templates/quote.html Normal file
View file

@ -0,0 +1,14 @@
{% extends "layout.html" %}
{% block customhead %}
<title>{{ title }}</title>
{% endblock %}
{% block content %}
<div class="container">
<pre>
{{ quote.quote }}
</pre>
<p class="text-muted small">Tags: {% for tag in quote.tags %}<a href="/tag/{{tag}}">{{tag}}</a>{% if not loop.last %}, {% endif %}{% endfor %}</p>
</div>
{% endblock %}