page nav for photo gallery

This commit is contained in:
Rupus Reinefjord 2018-01-12 00:19:34 +01:00
parent a528892ac8
commit 15b1d3999a
4 changed files with 28 additions and 2 deletions

11
app.py
View file

@ -141,8 +141,15 @@ def index():
@app.route('/photo/', defaults={'page': 1})
@app.route('/photo/page/<int:page>')
def photography(page):
photos = Photo.select().order_by(Photo.timestamp.desc()).paginate(page, 9)
return flask.render_template('photography.html', photos=photos)
query = Photo.select().order_by(Photo.timestamp.desc())
photos = query.paginate(page, 9) or flask.abort(404)
has_next = bool(query.paginate(page+1, 9))
return flask.render_template('photography.html',
photos=photos,
page=page,
has_next=has_next)
@app.route('/photo/<int:photo_id>')

View file

@ -95,6 +95,15 @@ nav ul {
.view-image nav {
align-self: center;
}
.photo-grid + nav {
margin-left: auto;
margin-right: auto;
}
.view-image nav,
.photo-grid + nav {
margin-top: 2rem;
max-width: 24rem;
width: 100%;

View file

@ -16,5 +16,14 @@
</a>
{% endfor %}
</div>
<nav>
{% if page > 1 %}
<a href="{{ url_for('photography', page=page-1) }}" class="nav-item next">&larr; Newer</a>
{% endif %}
{% if has_next %}
<a href="{{ url_for('photography', page=page+1) }}" class="nav-item prev">Older &rarr;</a>
{% endif %}
</nav>
</main>
{% endblock %}

View file

@ -28,5 +28,6 @@
<a href="{{ url_for('view_photo', photo_id=prev.id) }}" class="nav-item prev">Previous &rarr;</a>
{% endif %}
{% endif %}
</nav>
</main>
{% endblock %}