-@app.route("/motion/<int:id>")
-def show_motion(id):
- p = get_db().prepare("SELECT motion.*, motion.deadline > CURRENT_TIMESTAMP AS running, vote.result FROM motion LEFT JOIN vote on vote.motion_id=motion.id AND vote.voter_id=$2 WHERE id=$1")
- rv = p(id,voter)
+def motion_edited(motion):
+ return redirect("/?start=" + str(motion) + "#motion-" + str(motion))
+
+@app.route("/motion/<int:id>/cancel", methods=['POST'])
+def cancel_motion(id):
+ if request.form.get("reason", "none") == "none":
+ return "Error, form requires reason"
+ rv = get_db().prepare("UPDATE motion SET canceled=CURRENT_TIMESTAMP, cancelation_reason=$1, canceled_by=$2 WHERE id=$3 AND canceled is NULL")(request.form.get("reason", ""), voter, id)
+ print(rv)
+ return motion_edited(id)
+
+@app.route("/motion/<int:motion>")
+def show_motion(motion):
+ p = get_db().prepare("SELECT motion.*, poser.email AS poser, canceler.email AS canceler, (motion.deadline > CURRENT_TIMESTAMP AND canceled is NULL) AS running, vote.result FROM motion "\
+ + "LEFT JOIN vote on vote.motion_id=motion.id AND vote.voter_id=$2 "\
+ + "LEFT JOIN voter poser ON poser.id = motion.posed_by "\
+ + "LEFT JOIN voter canceler ON canceler.id = motion.canceled_by "
+ + "WHERE motion.id=$1")
+ rv = p(motion,voter)
+ if len(rv) == 0:
+ return "Error, motion not found" # TODO 404