from flask import request
import postgresql
import config
+import filters
+times=[3,5,14]
def get_db():
db = getattr(g, '_database', None)
return db
app = Flask(__name__)
+app.register_blueprint(filters.blueprint)
+
+
@app.teardown_appcontext
def close_connection(exception):
+ "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)
+ 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():
- 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
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 authentication/user management