Migrate quote page to use SQLAlchemy

This commit is contained in:
nukeop 2017-01-02 14:29:10 +01:00
parent c07b2a6695
commit 5d1e6b62aa
2 changed files with 10 additions and 23 deletions

View file

@ -3,17 +3,17 @@
{% if quotes %} {% if quotes %}
{% for quote in quotes %} {% for quote in quotes %}
<a class="quote-link" href="quote/{{ quote[0] }}">#{{ quote[0] }}</a> <a class="quote-link" href="quote/{{ quote[0] }}">#{{ quote.id }}</a>
<a class="rate-positive">+</a> ({{quote[1]}}) <a class="rate-negative">-</a></br> <a class="rate-positive">+</a> ({{quote.rating}}) <a class="rate-negative">-</a></br>
<div class="quote"> <div class="quote">
<p>{{ quote[2]|safe }}</p> <p>{{ quote.content|safe }}</p>
</div> </div>
<div class="tags"> <div class="tags">
Tags: Tags:
{% for tag in quote[3] %} {% for tag in quote.tags %}
<a href="tag/{{tag}}" class="badge"> {{tag}} </a> <a href="tag/{{tag}}" class="badge"> {{tag.name}} </a>
{% endfor %} {% endfor %}
</div> </div>

View file

@ -79,34 +79,21 @@ def latest():
@app.route('/quote/<int:id>') @app.route('/quote/<int:id>')
def quote(id): def quote(id):
quote = db.select("quotes", "id, rating, content", "id='{}'".format(id)) quote = Quote.query.filter_by(id=id).first()
if len(quote)<1:
if quote is None:
return render_template( return render_template(
"message.html", "message.html",
alertclass="alert-warning", alertclass="alert-warning",
message="No such quote." message="No such quote."
) )
else: 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', '</br>'),
tags_str
)
]
return render_template( return render_template(
"latest.html", "latest.html",
appname=conf.config['APPNAME'], appname=conf.config['APPNAME'],
appbrand=conf.config['APPBRAND'], appbrand=conf.config['APPBRAND'],
title="Latest", title="Quote #{}".format(quote.id),
quotes=quote quotes=[quote,]
) )