- if time not in times:
- return "Error, invalid length", 500
- p = get_db().prepare("INSERT INTO motion(\"name\", \"content\", \"deadline\", \"posed_by\", \"type\") VALUES($1, $2, CURRENT_TIMESTAMP + $3 * interval '1 days', $4, $5)")
- p(request.form.get("title", ""), request.form.get("content",""), time, g.voter, cat)
- return redirect("/")
+ if time not in times.per_host:
+ return "Error, invalid length", 400
+ title=request.form.get("title", "")
+ title=title.strip()
+ if title =='':
+ return "Error, missing title", 400
+ content=request.form.get("content", "")
+ content=content.strip()
+ if content =='':
+ return "Error, missing content", 400
+
+ db = get_db()
+ with db.xact():
+ t = db.prepare("SELECT CURRENT_TIMESTAMP")()[0][0];
+ s = db.prepare("SELECT MAX(\"identifier\") FROM \"motion\" WHERE \"type\"=$1 AND \"host\"=$2 AND DATE(\"posed\")=DATE(CURRENT_TIMESTAMP)")
+ sr = s(cat, request.host)
+ ident=""
+ if len(sr) == 0 or sr[0][0] is None:
+ ident=prefix.per_host[cat]+"."+t.strftime("%Y%m%d")+".001"
+ else:
+ ident=prefix.per_host[cat]+"."+t.strftime("%Y%m%d")+"."+("%03d" % (int(sr[0][0].split(".")[2])+1))
+ p = db.prepare("INSERT INTO motion(\"name\", \"content\", \"deadline\", \"posed_by\", \"type\", \"identifier\", \"host\") VALUES($1, $2, CURRENT_TIMESTAMP + $3 * interval '1 days', $4, $5, $6, $7)")
+ p(title, content, time, g.voter, cat, ident, request.host)
+ return rel_redirect("/")