import postgresql
import config
+times=[3,5,14]
def get_db():
db = getattr(g, '_database', None)
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
{% 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-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">
- <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>