Individual quote pages
This commit is contained in:
parent
478e9dba1b
commit
20c3432e6d
4 changed files with 33 additions and 3 deletions
7
db.py
7
db.py
|
@ -5,6 +5,7 @@ qdb = db.quotes
|
||||||
adb = db.accounts
|
adb = db.accounts
|
||||||
|
|
||||||
live_quotes_count = lambda: qdb.find({ "hidden": False, "approved": True })
|
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():
|
def get_random_quote():
|
||||||
|
|
||||||
|
@ -16,6 +17,12 @@ def get_random_quote():
|
||||||
|
|
||||||
return(x if x else False)
|
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):
|
def add_quote(quote, tags, author):
|
||||||
qdb.insert_one({
|
qdb.insert_one({
|
||||||
"id": nanoid.generate(size=12),
|
"id": nanoid.generate(size=12),
|
||||||
|
|
8
main.py
8
main.py
|
@ -61,5 +61,13 @@ def tags():
|
||||||
tags=db.count_live_quotes_by_tag()
|
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__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", debug=True)
|
app.run(host="0.0.0.0", debug=True)
|
||||||
|
|
|
@ -11,12 +11,13 @@
|
||||||
{% for quote in quotes %}
|
{% for quote in quotes %}
|
||||||
<div>
|
<div>
|
||||||
<div class="d-flex justify-content-between">
|
<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>
|
<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 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>
|
<button class="btn btn-link text-danger btn-sm"><i class="fas fa-times"></i></button>
|
||||||
</span>
|
</span>
|
||||||
|
-->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<pre>{{ quote.quote }}</pre>
|
<pre>{{ quote.quote }}</pre>
|
||||||
|
|
14
templates/quote.html
Normal file
14
templates/quote.html
Normal 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 %}
|
Loading…
Add table
Reference in a new issue