From 5d1e6b62aa5d80d9f45276cc4200298ba372d55a Mon Sep 17 00:00:00 2001 From: nukeop Date: Mon, 2 Jan 2017 14:29:10 +0100 Subject: [PATCH] Migrate quote page to use SQLAlchemy --- smash/templates/latest.html | 10 +++++----- smash/views.py | 23 +++++------------------ 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/smash/templates/latest.html b/smash/templates/latest.html index f267c23..579ef15 100644 --- a/smash/templates/latest.html +++ b/smash/templates/latest.html @@ -3,17 +3,17 @@ {% if quotes %} {% for quote in quotes %} -#{{ quote[0] }} -+ ({{quote[1]}}) -
+#{{ quote.id }} ++ ({{quote.rating}}) -
-

{{ quote[2]|safe }}

+

{{ quote.content|safe }}

Tags: - {% for tag in quote[3] %} - {{tag}} + {% for tag in quote.tags %} + {{tag.name}} {% endfor %}
diff --git a/smash/views.py b/smash/views.py index 07e313c..51fb1fd 100644 --- a/smash/views.py +++ b/smash/views.py @@ -79,34 +79,21 @@ def latest(): @app.route('/quote/') def quote(id): - quote = db.select("quotes", "id, rating, content", "id='{}'".format(id)) - if len(quote)<1: + quote = Quote.query.filter_by(id=id).first() + + if quote is None: return render_template( "message.html", alertclass="alert-warning", message="No such quote." ) else: - - tags = db.select("tagsToQuotes", "tagid", "quoteid='{}'".format(quote[0][0])) - tags_str = [] - for tag in tags: - tags_str.append(db.select("tags", "name", "id='{}'".format(tag[0]))[0][0]) - - quote = [ - ( - quote[0][0], - quote[0][1], - unicode(Markup.escape(quote[0][2])).replace('\n', '
'), - tags_str - ) - ] return render_template( "latest.html", appname=conf.config['APPNAME'], appbrand=conf.config['APPBRAND'], - title="Latest", - quotes=quote + title="Quote #{}".format(quote.id), + quotes=[quote,] )