]> WPIA git - motion.git/blobdiff - motion.py
upd: make duration of motions configurable
[motion.git] / motion.py
index c806f7a6a886710037c75ca5a502a2278c2ab7c0..f835f99d53bdd277645c0284ff4035f98a9c8cba 100644 (file)
--- a/motion.py
+++ b/motion.py
@@ -5,8 +5,6 @@ from flask import request
 import postgresql
 import filters
 
-times=[3,5,14]
-
 def get_db():
     db = getattr(g, '_database', None)
     if db is None:
@@ -22,6 +20,8 @@ app.config.from_pyfile('config.py')
 
 prefix=app.config.get("GROUP_PREFIX")
 
+times=app.config.get("DURATION")
+
 @app.before_request
 def lookup_user():
     global prefix
@@ -37,6 +37,7 @@ def lookup_user():
         user = env.get("USER")
         roles = env.get("ROLES")
 
+
     if user is None:
         return "Server misconfigured", 500
     roles = roles.split(" ")
@@ -56,13 +57,14 @@ def lookup_user():
 
     for r in roles:
         a = r.split(":", 1)
-        val = a[1]
-        if a[0] not in g.roles:
-            g.roles[a[0]] = []
-        if val == "*":
-            g.roles[a[0]] = [group for group in prefix[request.host]]
-        else:
-            g.roles[a[0]].append(val)
+        if len(r)!=0:
+            val = a[1]
+            if a[0] not in g.roles:
+                g.roles[a[0]] = []
+            if val == "*":
+                g.roles[a[0]] = [group for group in prefix[request.host]]
+            else:
+                g.roles[a[0]].append(val)
     return None
 
 def get_allowed_cats(action):
@@ -143,7 +145,7 @@ def main():
             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,
+    return render_template('index.html', motions=rv[:10], more=rv[10]["id"] if len(rv) == 11 else None, times=times[request.host], prev=prev,
                            categories=get_allowed_cats("create"))
 
 def rel_redirect(loc):
@@ -157,12 +159,12 @@ def put_motion():
     if cat not in get_allowed_cats("create"):
         return "Forbidden", 403
     time = int(request.form.get("days", "3"));
-    if time not in times:
+    if time not in times[request.host]:
         return "Error, invalid length", 500
     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 DATE(\"posed\")=DATE(CURRENT_TIMESTAMP)")
+        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:
@@ -178,7 +180,7 @@ def motion_edited(motion):
 
 @app.route("/motion/<string:motion>/cancel", methods=['POST'])
 def cancel_motion(motion):
-    rv = get_db().prepare("SELECT id, type FROM motion WHERE identifier=$1 AND request.host")(motion, request.host);
+    rv = get_db().prepare("SELECT id, type FROM motion WHERE identifier=$1 AND host=$2")(motion, request.host);
     if len(rv) == 0:
         return "Error, Not found", 404
     id = rv[0].get("id")
@@ -207,7 +209,7 @@ def vote(motion):
     v = request.form.get("vote", "abstain")
     db = get_db()
     with db.xact():
-        rv = db.prepare("SELECT id, type FROM motion WHERE identifier=$1 AND host=$2")(motion, host);
+        rv = db.prepare("SELECT id, type FROM motion WHERE identifier=$1 AND host=$2")(motion, request.host);
         if len(rv) == 0:
             return "Error, Not found", 404
         if not may("vote", rv[0].get("type")):
@@ -216,8 +218,8 @@ def vote(motion):
         id = rv[0].get("id")
         if not p(motion, request.host)[0][0]:
             return "Error, motion deadline has passed", 500
-        p = db.prepare("SELECT * FROM vote WHERE motion_id = $1 AND voter_id = $2 AND host=$3")
-        rv = p(id, g.voter, request.host)
+        p = db.prepare("SELECT * FROM vote WHERE motion_id = $1 AND voter_id = $2")
+        rv = p(id, g.voter)
         if len(rv) == 0:
             db.prepare("INSERT INTO vote(motion_id, voter_id, result) VALUES($1,$2,$3)")(id, g.voter, v)
         else: