From 755d275d1bd47a0d480834ad4c6255691a3a798b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Wed, 15 Nov 2017 14:06:14 +0100 Subject: [PATCH] add: 'Prev' Pagination link --- motion.py | 11 ++++++++--- templates/index.html | 7 +++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/motion.py b/motion.py index 0f0da5d..9011d37 100644 --- a/motion.py +++ b/motion.py @@ -36,13 +36,19 @@ def main(): + "COUNT(CASE WHEN result='no' THEN 'no' ELSE NULL END) as no, "\ + "COUNT(CASE WHEN result='abstain' THEN 'abstain' ELSE NULL END) as abstain "\ + "FROM vote GROUP BY motion_id, voter_id) as votes ON votes.motion_id=motion.id " + prev=None if start == -1: p = get_db().prepare(q + "ORDER BY id DESC LIMIT 11") rv = p() else: p = get_db().prepare(q + "WHERE id <= $1 ORDER BY id DESC LIMIT 11") rv = p(start) - return render_template('index.html', motions=rv[:10], more=rv[10]["id"] if len(rv) == 11 else None, times=times) + rs = get_db().prepare("SELECT id FROM motion WHERE id > $1 ORDER BY id ASC LIMIT 10")(start) + if len(rs) == 10: + prev = rs[9][0] + else: + prev = -1 + return render_template('index.html', motions=rv[:10], more=rv[10]["id"] if len(rv) == 11 else None, times=times, prev=prev) @app.route("/motion", methods=['POST']) def put_motion(): @@ -75,9 +81,8 @@ def vote(motion): db.prepare("INSERT INTO vote (motion_id, voter_id, result) VALUES($1,$2,$3)")(motion,voter,v) else: db.prepare("UPDATE vote SET result=$3, entered=CURRENT_TIMESTAMP WHERE motion_id=$1 AND voter_id = $2")(motion,voter,v) - return redirect("/motion/" + str(motion)) + return redirect("/?start=" + str(motion) + "#motion-" + str(motion)) # TODO cancel running motion (with comment) -# TODO pagination previous link # TODO authentication/user management # TODO crop time at second precision diff --git a/templates/index.html b/templates/index.html index 6e18c96..9175db6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,6 +17,13 @@ +{% if prev %} +{% if prev == -1 %} +Prev +{% else %} +Prev +{% endif %} +{% endif %} {% for motion in motions %} {% include 'motion.html' %} {% endfor %} -- 2.39.2