View quotes by tag

This commit is contained in:
Kate 2020-11-18 02:49:45 +00:00
parent 20c3432e6d
commit 7191b39711
5 changed files with 20 additions and 8 deletions

3
db.py
View file

@ -41,7 +41,8 @@ def get_latest_quotes(page=1):
def get_live_quotes_by_tag(tag):
return list(qdb \
.find({ "hidden": False, "approved": True, "tags": tag}))
.find({ "hidden": False, "approved": True, "tags": tag}) \
.sort( "_id", 1 ))
def get_all_tags():
return qdb \

12
main.py
View file

@ -47,8 +47,9 @@ def index():
@app.route('/latest')
def latest():
return render_template(
"latest.html",
"list.html",
title="Latest",
header="Latest Quotes",
quotes=db.get_latest_quotes()
)
@ -61,6 +62,15 @@ def tags():
tags=db.count_live_quotes_by_tag()
)
@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)
)
@app.route('/quote/<quote_id>')
def quote(quote_id):
return render_template(

View file

@ -6,7 +6,7 @@
{% block content %}
<div class="container">
<h1 class="display-4 mb-5">Latest Quotes</h1>
<h1 class="display-4 mb-5">{{ header }}</h1>
{% for quote in quotes %}
<div>
@ -22,9 +22,10 @@
<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>
<p class="text-muted small">Tags: {% for tag in quote.tags %}<a href="/tags/{{tag}}">{{tag}}</a>{% if not loop.last %}, {% endif %}{% endfor %}</p>
</div>
{% if not loop.last %}<hr />{% endif %}
{% endfor %}
</div>

View file

@ -8,7 +8,7 @@
<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>
<p class="text-muted small">Tags: {% for tag in quote.tags %}<a href="/tags/{{tag}}">{{tag}}</a>{% if not loop.last %}, {% endif %}{% endfor %}</p>
</div>
{% endblock %}

View file

@ -11,14 +11,14 @@
<div class="col-12 col-md-5">
<ul class="list-group">
{% for tag,count in tags.items() %}
<li class="list-group-item d-flex justify-content-between align-items-center">
<a href="/tags/{{ tag }}" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
{{ tag }}
<span class="badge badge-primary badge-pill">{{ count }}</span>
</li>
</a>
{% endfor %}
</ul>
</div>
</div>
{% endblock %}