Migrate latest page to SQLAlchemy
This commit is contained in:
parent
5d1e6b62aa
commit
d034d8e989
2 changed files with 8 additions and 21 deletions
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
{% if quotes %}
|
{% if quotes %}
|
||||||
{% for quote in quotes %}
|
{% for quote in quotes %}
|
||||||
<a class="quote-link" href="quote/{{ quote[0] }}">#{{ quote.id }}</a>
|
<a class="quote-link" href="quote/{{ quote.id }}">#{{ quote.id }}</a>
|
||||||
<a class="rate-positive">+</a> ({{quote.rating}}) <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.content|safe }}</p>
|
<p>{{ quote.content|safe }}</p>
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
Tags:
|
Tags:
|
||||||
{% for tag in quote.tags %}
|
{% for tag in quote.tags %}
|
||||||
<a href="tag/{{tag}}" class="badge"> {{tag.name}} </a>
|
<a href="tag/{{tag.name}}" class="badge"> {{tag.name}} </a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -48,38 +48,24 @@ def login_page():
|
||||||
|
|
||||||
@app.route('/latest')
|
@app.route('/latest')
|
||||||
def latest():
|
def latest():
|
||||||
quotes = reversed(db.select("quotes", "id, rating, content", "approved"))
|
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()
|
||||||
quotes = [(q[0], q[1], unicode(Markup.escape(q[2])).replace('\n', '</br>')) for q in quotes]
|
|
||||||
|
|
||||||
quotes_tags = []
|
|
||||||
|
|
||||||
|
# Replace line breaks with html breaks and escape special characters
|
||||||
for quote in quotes:
|
for quote in quotes:
|
||||||
tags = db.select("tagsToQuotes", "tagid", "quoteid='{}'".format(quote[0]))
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
tags_str = []
|
|
||||||
for tag in tags:
|
|
||||||
tags_str.append(db.select("tags", "name", "id='{}'".format(tag[0]))[0][0])
|
|
||||||
|
|
||||||
quotes_tags.append(
|
|
||||||
(
|
|
||||||
quote[0],
|
|
||||||
quote[1],
|
|
||||||
quote[2],
|
|
||||||
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="Latest",
|
||||||
quotes=quotes_tags
|
quotes=quotes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/quote/<int:id>')
|
@app.route('/quote/<int:id>')
|
||||||
def quote(id):
|
def quote(id):
|
||||||
quote = Quote.query.filter_by(id=id).first()
|
quote = Quote.query.filter_by(id=id, approved=True).first()
|
||||||
|
|
||||||
if quote is None:
|
if quote is None:
|
||||||
return render_template(
|
return render_template(
|
||||||
|
@ -88,6 +74,7 @@ def quote(id):
|
||||||
message="No such quote."
|
message="No such quote."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
appname=conf.config['APPNAME'],
|
appname=conf.config['APPNAME'],
|
||||||
|
|
Loading…
Add table
Reference in a new issue