X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=motion.py;h=ef98529fb19150a29245b13b522a1c68ff843ef0;hb=301d8033d5489c65bde7df0f32013983647ff0da;hp=f6ddf1344004ee30bd5bbb40d096eadcd33cea90;hpb=fd16e7d1b4090b8466997b98ce84e5a9d9ebc4d0;p=motion.git diff --git a/motion.py b/motion.py index f6ddf13..ef98529 100644 --- a/motion.py +++ b/motion.py @@ -27,11 +27,20 @@ md = Markdown(app, extensions=[EscapeHtml()]) # Load config app.config.from_pyfile('config.py') -prefix=app.config.get("GROUP_PREFIX") -times=app.config.get("DURATION") +class ConfigProxy: + def __init__(self, name): + self.name = name + @property + def per_host(self): + dict = app.config.get(self.name) + if dict is None: + return None + return dict.get(request.host) -debuguser=app.config.get("DEBUGUSER") +prefix = ConfigProxy("GROUP_PREFIX") +times = ConfigProxy("DURATION") +debuguser = ConfigProxy("DEBUGUSER") @app.before_request def lookup_user(): @@ -39,8 +48,9 @@ def lookup_user(): env = request.environ user = None - if debuguser is not None: - parts =debuguser[request.host].split("/", 1) + my_debuguser = debuguser.per_host + if my_debuguser is not None: + parts = my_debuguser.split("/", 1) user = parts[0] roles = parts[1] @@ -78,7 +88,7 @@ def lookup_user(): if a[0] not in g.roles: g.roles[a[0]] = [] if val == "*": - g.roles[a[0]] = [group for group in prefix[request.host]] + g.roles[a[0]] = [group for group in prefix.per_host] else: g.roles[a[0]].append(val) return None @@ -161,7 +171,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[request.host], prev=prev, + return render_template('index.html', motions=rv[:10], more=rv[10]["id"] if len(rv) == 11 else None, times=times.per_host, prev=prev, categories=get_allowed_cats("create")) def rel_redirect(loc): @@ -175,7 +185,7 @@ 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[request.host]: + if time not in times.per_host: return "Error, invalid length", 500 db = get_db() with db.xact(): @@ -184,9 +194,9 @@ def put_motion(): sr = s(cat, request.host) ident="" if len(sr) == 0 or sr[0][0] is None: - ident=prefix[request.host][cat]+"."+t.strftime("%Y%m%d")+".001" + ident=prefix.per_host[cat]+"."+t.strftime("%Y%m%d")+".001" else: - ident=prefix[request.host][cat]+"."+t.strftime("%Y%m%d")+"."+("%03d" % (int(sr[0][0].split(".")[2])+1)) + 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(request.form.get("title", ""), request.form.get("content",""), time, g.voter, cat, ident, request.host) return rel_redirect("/")