Tags page

This commit is contained in:
nukeop 2017-01-03 23:08:11 +01:00
parent e943fd880b
commit b301496421
3 changed files with 23 additions and 4 deletions

View file

@ -26,7 +26,7 @@
Tags:
{% if quote.tags|length > 0 and quote.tags[0].name|length>0%}
{% for tag in quote.tags %}
<a href="tag/{{tag.name}}" class="badge"> {{tag.name}} </a>
<a href="/tag/{{tag.name}}" class="badge"> {{tag.name}} </a>
{% endfor %}
{% else %}
<strong> No tags </strong>

View file

@ -2,7 +2,7 @@
{% block content %}
{% for tag in tags %}
<a class="badge">{{tag.name}}</a><br />
<a class="badge" href="/tag/{{tag}}">{{tag}}</a><br />
{% endfor %}
{% endblock %}

View file

@ -135,10 +135,29 @@ def quote(id):
)
@app.route('/tag/<tagname>')
def tag(tagname):
tag = Tag.query.filter_by(name=tagname).first()
if len(list(tag.quotes))>0:
# Replace line breaks with html breaks and escape special characters
for quote in tag.quotes:
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
return render_template(
"latest.html",
title="Latest",
quotes=tag.quotes
)
else:
return message("alert-warning", "No quotes with this tag.")
@app.route('/tags')
def tags():
tags = Tag.query.order_by(Tag.name).all()
tags = Tag.query.order_by(Tag.name).distinct().all()
tags = list(set([x.name for x in tags]))
return render_template(
"tags.html",
title="Tags",