]> WPIA git - motion.git/commitdiff
upd: make duration of motions configurable
authorINOPIAE <m.maengel@inopiae.de>
Sat, 6 Apr 2019 02:30:40 +0000 (04:30 +0200)
committerINOPIAE <m.maengel@inopiae.de>
Sun, 22 Mar 2020 12:22:27 +0000 (13:22 +0100)
config.py.example
motion.py

index dcd7c8db99d3d39c959a2fb1e484a52b5730e4ac..3ad653f2a81cc4fa6e59bf9fee9de0c4a398b281 100644 (file)
@@ -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
index 51f21dee8070a233c553e3f8e45169b612e494f8..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
@@ -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():