Commit 378701af authored by Julian Rother's avatar Julian Rother
Browse files

Use @mod_required to decide if navitem is public

parent 3259f87d
...@@ -22,6 +22,7 @@ if __name__ == '__main__': ...@@ -22,6 +22,7 @@ if __name__ == '__main__':
config['DEBUG'] = True config['DEBUG'] = True
config.from_pyfile('config.py', silent=True) config.from_pyfile('config.py', silent=True)
app.jinja_env.globals['videoprefix'] = config['VIDEOPREFIX'] app.jinja_env.globals['videoprefix'] = config['VIDEOPREFIX']
mod_endpoints = []
if config['DB_ENGINE'] == 'sqlite': if config['DB_ENGINE'] == 'sqlite':
created = not os.path.exists(config['SQLITE_DB']) created = not os.path.exists(config['SQLITE_DB'])
...@@ -127,6 +128,7 @@ def ismod(*args): ...@@ -127,6 +128,7 @@ def ismod(*args):
app.jinja_env.globals['ismod'] = ismod app.jinja_env.globals['ismod'] = ismod
def mod_required(func): def mod_required(func):
mod_endpoints.append(func.__name__)
@wraps(func) @wraps(func)
def decorator(*args, **kwargs): def decorator(*args, **kwargs):
if not ismod(): if not ismod():
...@@ -134,12 +136,15 @@ def mod_required(func): ...@@ -134,12 +136,15 @@ def mod_required(func):
return redirect(url_for('login', ref=request.url)) return redirect(url_for('login', ref=request.url))
else: else:
return func(*args, **kwargs) return func(*args, **kwargs)
print(decorator.__name__)
return decorator return decorator
app.jinja_env.globals['navbar'] = [] app.jinja_env.globals['navbar'] = []
def register_navbar(name, icon=None, visible=True): def register_navbar(name, icon=None):
def wrapper(func): def wrapper(func):
app.jinja_env.globals['navbar'].append((func.__name__, name, icon, visible)) endpoint = func.__name__
app.jinja_env.globals['navbar'].append((endpoint, name, icon,
not endpoint in mod_endpoints))
return func return func
return wrapper return wrapper
...@@ -297,7 +302,8 @@ def auth(): # For use with nginx auth_request ...@@ -297,7 +302,8 @@ def auth(): # For use with nginx auth_request
@app.route('/schedule') @app.route('/schedule')
@register_navbar('Drehplan', 'calendar', visible=False) @register_navbar('Drehplan', 'calendar')
@mod_required
def schedule(): def schedule():
return render_template('schedule.html') return render_template('schedule.html')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment