From 3a43e923fd7253d358f0c9deb4f79ed8ee317caf Mon Sep 17 00:00:00 2001 From: INOPIAE Date: Sat, 6 Apr 2019 04:30:40 +0200 Subject: [PATCH] upd: make duration of motions configurable --- config.py.example | 2 ++ motion.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config.py.example b/config.py.example index dcd7c8d..3ad653f 100644 --- a/config.py.example +++ b/config.py.example @@ -5,3 +5,5 @@ PASSWORD="..." DEFAULT_HOST="hostname for migration from db version < 2" GROUP_PREFIX={'hostname': {'group1': 'g1', 'group2': 'g2'}} # motion types and their id-prefixes + +DURATION={'hostname':[3, 7, 14]} # duration period for motions diff --git a/motion.py b/motion.py index 51f21de..f835f99 100644 --- 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 @@ -145,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): @@ -159,7 +159,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: + if time not in times[request.host]: return "Error, invalid length", 500 db = get_db() with db.xact(): -- 2.39.2