Pagination for tags
This commit is contained in:
parent
fa327a95e5
commit
e93c951458
1 changed files with 32 additions and 4 deletions
|
@ -17,7 +17,8 @@ def message(level, msg):
|
||||||
return render_template(
|
return render_template(
|
||||||
"message.html",
|
"message.html",
|
||||||
alertclass=level,
|
alertclass=level,
|
||||||
message=msg
|
message=msg,
|
||||||
|
title="Message"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ def latest_page(page):
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
title="Latest",
|
title="Latest - page {}".format(page),
|
||||||
quotes=quotes,
|
quotes=quotes,
|
||||||
numpages=1 + allquotes//10,
|
numpages=1 + allquotes//10,
|
||||||
curpage=page-1,
|
curpage=page-1,
|
||||||
|
@ -162,19 +163,46 @@ def tag(tagname):
|
||||||
tag = Tag.query.filter_by(name=tagname).first()
|
tag = Tag.query.filter_by(name=tagname).first()
|
||||||
|
|
||||||
if len(list(tag.quotes))>0:
|
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
|
# Replace line breaks with html breaks and escape special characters
|
||||||
for quote in tag.quotes:
|
for quote in tag.quotes:
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
title="Latest",
|
title="Tag - {}".format(tagname),
|
||||||
quotes=tag.quotes
|
quotes=tag.quotes,
|
||||||
|
numpages=1 + allquotes//10,
|
||||||
|
curpage=0,
|
||||||
|
page_type="tag/{}".format(tagname)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return message("alert-warning", "No quotes with this tag.")
|
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')
|
@app.route('/tags')
|
||||||
def tags():
|
def tags():
|
||||||
tags = Tag.query.order_by(Tag.name).distinct().all()
|
tags = Tag.query.order_by(Tag.name).distinct().all()
|
||||||
|
|
Loading…
Add table
Reference in a new issue