]> WPIA git - motion.git/commitdiff
add: dropdown to choose length of motion
authorFelix Dörre <felix@dogcraft.de>
Wed, 15 Nov 2017 13:01:37 +0000 (14:01 +0100)
committerFelix Dörre <felix@dogcraft.de>
Wed, 15 Nov 2017 13:04:42 +0000 (14:04 +0100)
motion.py
templates/index.html

index 5d069d99275f4b5ab07d277709d832a0b15d8bb6..0f0da5def3eb7dbabf0e948745a588221943c8f1 100644 (file)
--- a/motion.py
+++ b/motion.py
@@ -5,6 +5,7 @@ from flask import request
 import postgresql
 import config
 
 import postgresql
 import config
 
+times=[3,5,14]
 
 def get_db():
     db = getattr(g, '_database', None)
 
 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)
     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():
 
 @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
     return redirect("/")
 
 voter=1
index 57a73f8698104a66202a5e1c8fe60f80301d81bb..6e18c960ca9d09d2f9a837b90d6bb8c43167dc9b 100644 (file)
@@ -1,11 +1,18 @@
 {% extends "base.html" %}
 {% block body %}
 <div class="container">
 {% extends "base.html" %}
 {% block body %}
 <div class="container">
-<form action="/motion" method="POST">
+<form action="/motion" method="POST" class="form-inline">
 <div class="motion panel panel-default">
 <div class="motion panel panel-default">
-  <div class="motion-title panel-heading"><input class="form-control" placeholder="Motion title" type="text" name="title" id="title"></div>
+  <div class="motion-title panel-heading from-group">
+    <input class="form-control" placeholder="Motion title" type="text" name="title" id="title">
+    <select class="form-control" name="days">
+      {%- for time in times %}
+      <option>{{time}}</option>
+      {%- endfor %}
+    </select>
+  </div>
   <div class="panel-body">
   <div class="panel-body">
-    <textarea class="form-control" placeholder="Motion content" name="content" rows="8" cols="70"></textarea>
+    <textarea class="form-control" placeholder="Motion content" name="content" rows="8" cols="70"></textarea><br>
     <button class="btn btn-primary" type="submit">Submit Motion</button>
   </div>
 </div>
     <button class="btn btn-primary" type="submit">Submit Motion</button>
   </div>
 </div>