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';
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
@ -146,14 +146,28 @@ html, body {
|
|||
.badge {
|
||||
background-color: #03A9F4;
|
||||
}
|
||||
|
||||
.mod-form {
|
||||
padding-left: 8px;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.mod-form {
|
||||
padding-left: 8px;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.btn-mod {
|
||||
padding: 0px 4px;
|
||||
border-radius: 0px;
|
||||
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" %}
|
||||
{% 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 %}
|
||||
{% for quote in quotes %}
|
||||
<div class="quote-header">
|
||||
<a class="quote-link" href="quote/{{ quote.id }}">#{{ quote.id }}</a>
|
||||
<a class="rate-positive">+</a> ({{quote.rating}}) <a class="rate-negative">-</a>
|
||||
<div class="pull-right quote-date">{{ quote.time }}</div>
|
||||
{% for quote in quotes %}
|
||||
{% if quote.approved %}
|
||||
<div class="quote-header">
|
||||
<a class="quote-link" href="/quote/{{ quote.id }}">#{{ quote.id }}</a>
|
||||
<a class="rate-positive">+</a> ({{quote.rating}}) <a class="rate-negative">-</a>
|
||||
<div class="pull-right quote-date">{{ quote.time }}</div>
|
||||
|
||||
{% if session.authorized %}
|
||||
<form class="mod-form" action="/moderate" name="moderate" method="post">
|
||||
<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>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if session.authorized %}
|
||||
<form class="mod-form" action="/moderate" name="moderate" method="post">
|
||||
<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>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
<div class="quote">
|
||||
<p>{{ quote.content|safe }}</p>
|
||||
</div>
|
||||
<div class="quote">
|
||||
<p>{{ quote.content|safe }}</p>
|
||||
</div>
|
||||
|
||||
<div class="tags">
|
||||
<div class="tags">
|
||||
|
||||
Tags:
|
||||
{% if quote.tags|length > 0 and quote.tags[0].name|length>0%}
|
||||
{% for tag in quote.tags %}
|
||||
<a href="/tag/{{tag.name}}" class="badge"> {{tag.name}} </a>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<strong> No tags </strong>
|
||||
Tags:
|
||||
{% if quote.tags|length > 0 and quote.tags[0].name|length>0%}
|
||||
{% for tag in quote.tags %}
|
||||
<a href="/tag/{{tag.name}}" class="badge"> {{tag.name}} </a>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<strong> No tags </strong>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -58,6 +58,8 @@ def login_page():
|
|||
@app.route('/latest')
|
||||
def latest():
|
||||
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()
|
||||
allquotes = len(quotes)
|
||||
quotes = quotes[:10]
|
||||
|
||||
if len(quotes)>0:
|
||||
# Replace line breaks with html breaks and escape special characters
|
||||
|
@ -67,12 +69,32 @@ def latest():
|
|||
return render_template(
|
||||
"latest.html",
|
||||
title="Latest",
|
||||
quotes=quotes
|
||||
quotes=quotes,
|
||||
numpages=1 + allquotes//10,
|
||||
curpage=0,
|
||||
page_type="latest"
|
||||
)
|
||||
else:
|
||||
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')
|
||||
def queue():
|
||||
if not session.get('authorized'):
|
||||
|
|
Loading…
Add table
Reference in a new issue