From b30149642172c084811a5bc0d97be96cd8b4bc6f Mon Sep 17 00:00:00 2001 From: nukeop Date: Tue, 3 Jan 2017 23:08:11 +0100 Subject: [PATCH] Tags page --- smash/templates/latest.html | 2 +- smash/templates/tags.html | 2 +- smash/views.py | 23 +++++++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/smash/templates/latest.html b/smash/templates/latest.html index 0e047e0..3c3075e 100644 --- a/smash/templates/latest.html +++ b/smash/templates/latest.html @@ -26,7 +26,7 @@ Tags: {% if quote.tags|length > 0 and quote.tags[0].name|length>0%} {% for tag in quote.tags %} - {{tag.name}} + {{tag.name}} {% endfor %} {% else %} No tags diff --git a/smash/templates/tags.html b/smash/templates/tags.html index 9c92965..848b490 100644 --- a/smash/templates/tags.html +++ b/smash/templates/tags.html @@ -2,7 +2,7 @@ {% block content %} {% for tag in tags %} - {{tag.name}}
+ {{tag}}
{% endfor %} {% endblock %} diff --git a/smash/views.py b/smash/views.py index 39f6cce..be6a1fc 100644 --- a/smash/views.py +++ b/smash/views.py @@ -135,10 +135,29 @@ def quote(id): ) +@app.route('/tag/') +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', '
') + + 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",