Pagination for tags

This commit is contained in:
nukeop 2017-01-06 19:08:32 +01:00
parent fa327a95e5
commit e93c951458

View file

@ -17,7 +17,8 @@ def message(level, msg):
return render_template(
"message.html",
alertclass=level,
message=msg
message=msg,
title="Message"
)
@ -88,7 +89,7 @@ def latest_page(page):
return render_template(
"latest.html",
title="Latest",
title="Latest - page {}".format(page),
quotes=quotes,
numpages=1 + allquotes//10,
curpage=page-1,
@ -162,19 +163,46 @@ def tag(tagname):
tag = Tag.query.filter_by(name=tagname).first()
if len(list(tag.quotes))>0:
allquotes = len(list(tag.quotes))
tag.quotes = tag.quotes[:10]
# 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
title="Tag - {}".format(tagname),
quotes=tag.quotes,
numpages=1 + allquotes//10,
curpage=0,
page_type="tag/{}".format(tagname)
)
else:
return message("alert-warning", "No quotes with this tag.")
@app.route('/tag/<tagname>/<int:page>')
def tag_page(tagname, page):
tag = Tag.query.filter_by(name=tagname).first()
if len(list(tag.quotes))>0:
allquotes = len(list(tag.quotes))
tag.quotes = tag.quotes[(page-1)*10:page*10]
for quote in tag.quotes:
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
return render_template(
"latest.html",
title="Tag - {} - page {}".format(tagname, page),
quotes=tag.quotes,
numpages=1 + allquotes//10,
curpage=0,
page_type="tag/{}".format(tagname)
)
@app.route('/tags')
def tags():
tags = Tag.query.order_by(Tag.name).distinct().all()