Error message template
This commit is contained in:
parent
7191b39711
commit
75d11d6045
3 changed files with 33 additions and 6 deletions
1
db.py
1
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():
|
||||
|
||||
|
|
24
main.py
24
main.py
|
@ -64,12 +64,24 @@ def tags():
|
|||
|
||||
@app.route('/tags/<t>')
|
||||
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/<quote_id>')
|
||||
def quote(quote_id):
|
||||
|
|
14
templates/message.html
Normal file
14
templates/message.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends "layout.html" %}
|
||||
{% block customhead %}
|
||||
<title>{{ title }}</title>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
<div class="container">
|
||||
<div class="alert alert-{{ message.type }}" role="alert">
|
||||
<h4 class="alert-heading">{{ message.heading }}</h4>
|
||||
<p>{{ message.message }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
Loading…
Add table
Reference in a new issue