From fa327a95e537958cb5dcf8ff6f370d2b78e66a2a Mon Sep 17 00:00:00 2001 From: nukeop Date: Fri, 6 Jan 2017 16:52:14 +0100 Subject: [PATCH] Add simple pagination --- smash/static/css/custom.css | 26 +++++++++++---- smash/templates/latest.html | 66 ++++++++++++++++++++++--------------- smash/views.py | 24 +++++++++++++- 3 files changed, 83 insertions(+), 33 deletions(-) diff --git a/smash/static/css/custom.css b/smash/static/css/custom.css index 3498bb1..09caf97 100644 --- a/smash/static/css/custom.css +++ b/smash/static/css/custom.css @@ -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; } diff --git a/smash/templates/latest.html b/smash/templates/latest.html index 3c3075e..1cf6f03 100644 --- a/smash/templates/latest.html +++ b/smash/templates/latest.html @@ -1,39 +1,53 @@ {% extends "base.html" %} {% block content %} + + +{% if numpages>1 %} + +{% endif %} + {% if quotes %} -{% for quote in quotes %} -
- #{{ quote.id }} - + ({{quote.rating}}) - -
{{ quote.time }}
+ {% for quote in quotes %} + {% if quote.approved %} +
+ #{{ quote.id }} + + ({{quote.rating}}) - +
{{ quote.time }}
- {% if session.authorized %} -
- - -
- {% endif %} -
+ {% if session.authorized %} +
+ + +
+ {% endif %} +
-
-

{{ quote.content|safe }}

-
+
+

{{ quote.content|safe }}

+
-
+
- Tags: - {% if quote.tags|length > 0 and quote.tags[0].name|length>0%} - {% for tag in quote.tags %} - {{tag.name}} - {% endfor %} - {% else %} - No tags + Tags: + {% if quote.tags|length > 0 and quote.tags[0].name|length>0%} + {% for tag in quote.tags %} + {{tag.name}} + {% endfor %} + {% else %} + No tags + {% endif %} + +
{% endif %} - -
-{% endfor %} + {% endfor %} {% endif %} {% endblock %} diff --git a/smash/views.py b/smash/views.py index 8a0c797..3e6df4c 100644 --- a/smash/views.py +++ b/smash/views.py @@ -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/') +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', '
') + + 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'):