View quotes by tag
This commit is contained in:
parent
20c3432e6d
commit
7191b39711
5 changed files with 20 additions and 8 deletions
3
db.py
3
db.py
|
@ -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
12
main.py
|
@ -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(
|
||||
|
|
|
@ -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>
|
||||
|
|
@ -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 %}
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
<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>
|
||||
|
|
Loading…
Add table
Reference in a new issue