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):
|
def get_live_quotes_by_tag(tag):
|
||||||
return list(qdb \
|
return list(qdb \
|
||||||
.find({ "hidden": False, "approved": True, "tags": tag}))
|
.find({ "hidden": False, "approved": True, "tags": tag}) \
|
||||||
|
.sort( "_id", 1 ))
|
||||||
|
|
||||||
def get_all_tags():
|
def get_all_tags():
|
||||||
return qdb \
|
return qdb \
|
||||||
|
|
12
main.py
12
main.py
|
@ -47,8 +47,9 @@ def index():
|
||||||
@app.route('/latest')
|
@app.route('/latest')
|
||||||
def latest():
|
def latest():
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"list.html",
|
||||||
title="Latest",
|
title="Latest",
|
||||||
|
header="Latest Quotes",
|
||||||
quotes=db.get_latest_quotes()
|
quotes=db.get_latest_quotes()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -61,6 +62,15 @@ def tags():
|
||||||
tags=db.count_live_quotes_by_tag()
|
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>')
|
@app.route('/quote/<quote_id>')
|
||||||
def quote(quote_id):
|
def quote(quote_id):
|
||||||
return render_template(
|
return render_template(
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="display-4 mb-5">Latest Quotes</h1>
|
<h1 class="display-4 mb-5">{{ header }}</h1>
|
||||||
|
|
||||||
{% for quote in quotes %}
|
{% for quote in quotes %}
|
||||||
<div>
|
<div>
|
||||||
|
@ -22,9 +22,10 @@
|
||||||
|
|
||||||
<pre>{{ quote.quote }}</pre>
|
<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>
|
</div>
|
||||||
|
{% if not loop.last %}<hr />{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<pre>
|
<pre>
|
||||||
{{ quote.quote }}
|
{{ quote.quote }}
|
||||||
</pre>
|
</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>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
<div class="col-12 col-md-5">
|
<div class="col-12 col-md-5">
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{% for tag,count in tags.items() %}
|
{% 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 }}
|
{{ tag }}
|
||||||
<span class="badge badge-primary badge-pill">{{ count }}</span>
|
<span class="badge badge-primary badge-pill">{{ count }}</span>
|
||||||
</li>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue