Add simple pagination
This commit is contained in:
parent
ada370e59a
commit
fa327a95e5
3 changed files with 83 additions and 33 deletions
|
@ -1,4 +1,4 @@
|
||||||
html, body {
|
9 html, body {
|
||||||
font-family: 'Montserrat';
|
font-family: 'Montserrat';
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
@ -146,14 +146,28 @@ html, body {
|
||||||
.badge {
|
.badge {
|
||||||
background-color: #03A9F4;
|
background-color: #03A9F4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mod-form {
|
.mod-form {
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-mod {
|
.btn-mod {
|
||||||
padding: 0px 4px;
|
padding: 0px 4px;
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
display: inline;
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
margin: 0px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination>li>a {
|
||||||
|
color: #03A9F4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination>.active>a {
|
||||||
|
background-color: #03A9F4;
|
||||||
|
border-color: #03A9F4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,53 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% if numpages>1 %}
|
||||||
|
<ul class="pagination pagination-sm">
|
||||||
|
{% for page in range(numpages) %}
|
||||||
|
<li {% if curpage==page %} class="active" {% endif %} >
|
||||||
|
<a {% if curpage!=page %}href="/{{page_type}}/{{page+1}}"{% endif %}>{{page+1}}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if quotes %}
|
{% if quotes %}
|
||||||
{% for quote in quotes %}
|
{% for quote in quotes %}
|
||||||
<div class="quote-header">
|
{% if quote.approved %}
|
||||||
<a class="quote-link" href="quote/{{ quote.id }}">#{{ quote.id }}</a>
|
<div class="quote-header">
|
||||||
<a class="rate-positive">+</a> ({{quote.rating}}) <a class="rate-negative">-</a>
|
<a class="quote-link" href="/quote/{{ quote.id }}">#{{ quote.id }}</a>
|
||||||
<div class="pull-right quote-date">{{ quote.time }}</div>
|
<a class="rate-positive">+</a> ({{quote.rating}}) <a class="rate-negative">-</a>
|
||||||
|
<div class="pull-right quote-date">{{ quote.time }}</div>
|
||||||
|
|
||||||
{% if session.authorized %}
|
{% if session.authorized %}
|
||||||
<form class="mod-form" action="/moderate" name="moderate" method="post">
|
<form class="mod-form" action="/moderate" name="moderate" method="post">
|
||||||
<input type="hidden" name="quoteid" value={{quote.id}} />
|
<input type="hidden" name="quoteid" value={{quote.id}} />
|
||||||
<button type="submit" name="submit" class="btn btn-danger btn-sm btn-mod" value="Delete">Delete</button>
|
<button type="submit" name="submit" class="btn btn-danger btn-sm btn-mod" value="Delete">Delete</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="quote">
|
<div class="quote">
|
||||||
<p>{{ quote.content|safe }}</p>
|
<p>{{ quote.content|safe }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tags">
|
<div class="tags">
|
||||||
|
|
||||||
Tags:
|
Tags:
|
||||||
{% if quote.tags|length > 0 and quote.tags[0].name|length>0%}
|
{% if quote.tags|length > 0 and quote.tags[0].name|length>0%}
|
||||||
{% for tag in quote.tags %}
|
{% for tag in quote.tags %}
|
||||||
<a href="/tag/{{tag.name}}" class="badge"> {{tag.name}} </a>
|
<a href="/tag/{{tag.name}}" class="badge"> {{tag.name}} </a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<strong> No tags </strong>
|
<strong> No tags </strong>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -58,6 +58,8 @@ def login_page():
|
||||||
@app.route('/latest')
|
@app.route('/latest')
|
||||||
def latest():
|
def latest():
|
||||||
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()
|
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()
|
||||||
|
allquotes = len(quotes)
|
||||||
|
quotes = quotes[:10]
|
||||||
|
|
||||||
if len(quotes)>0:
|
if len(quotes)>0:
|
||||||
# Replace line breaks with html breaks and escape special characters
|
# Replace line breaks with html breaks and escape special characters
|
||||||
|
@ -67,12 +69,32 @@ def latest():
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
title="Latest",
|
title="Latest",
|
||||||
quotes=quotes
|
quotes=quotes,
|
||||||
|
numpages=1 + allquotes//10,
|
||||||
|
curpage=0,
|
||||||
|
page_type="latest"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return message("alert-warning", "No quotes in the database.")
|
return message("alert-warning", "No quotes in the database.")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/latest/<int:page>')
|
||||||
|
def latest_page(page):
|
||||||
|
allquotes = len(Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all())
|
||||||
|
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()[(page-1)*10:page*10]
|
||||||
|
|
||||||
|
for quote in quotes:
|
||||||
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"latest.html",
|
||||||
|
title="Latest",
|
||||||
|
quotes=quotes,
|
||||||
|
numpages=1 + allquotes//10,
|
||||||
|
curpage=page-1,
|
||||||
|
page_type="latest"
|
||||||
|
)
|
||||||
|
|
||||||
@app.route('/queue')
|
@app.route('/queue')
|
||||||
def queue():
|
def queue():
|
||||||
if not session.get('authorized'):
|
if not session.get('authorized'):
|
||||||
|
|
Loading…
Add table
Reference in a new issue