From f4f28c7000e23cf2aa0f4175d91f76315f7f394f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Wed, 15 Nov 2017 14:01:37 +0100 Subject: [PATCH] add: dropdown to choose length of motion --- motion.py | 10 +++++++--- templates/index.html | 13 ++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/motion.py b/motion.py index 5d069d9..0f0da5d 100644 --- a/motion.py +++ b/motion.py @@ -5,6 +5,7 @@ from flask import request import postgresql import config +times=[3,5,14] def get_db(): db = getattr(g, '_database', None) @@ -41,12 +42,15 @@ def main(): 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) + return render_template('index.html', motions=rv[:10], more=rv[10]["id"] if len(rv) == 11 else None, times=times) @app.route("/motion", methods=['POST']) def put_motion(): - p = get_db().prepare("INSERT INTO motion(\"name\", \"content\") VALUES($1, $2)") - p(request.form.get("title", ""), request.form.get("content","")) + time = int(request.form.get("days", "3")); + if time not in times: + return "Error, invalid length" + p = get_db().prepare("INSERT INTO motion(\"name\", \"content\", \"deadline\") VALUES($1, $2, CURRENT_TIMESTAMP + $3 * interval '1 days')") + p(request.form.get("title", ""), request.form.get("content",""), time) return redirect("/") voter=1 diff --git a/templates/index.html b/templates/index.html index 57a73f8..6e18c96 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,11 +1,18 @@ {% extends "base.html" %} {% block body %}
-
+
-
+
+ + +
- +
-- 2.39.2