From 30c5173aeaf700c7b03ad252541a353c47352d29 Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Wed, 2 Sep 2020 14:45:02 +0200 Subject: Implement scopes() view function This function provides the data needed to render the scopes.html template. --- ogcp/views.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'ogcp') diff --git a/ogcp/views.py b/ogcp/views.py index 4b03d2d..ad6bdaa 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -14,4 +14,24 @@ def index(): @app.route('/scopes/') def scopes(): - return render_template('base.html') + def add_state_to_scopes(scope, clients): + if 'ip' in scope: + filtered_client = filter(lambda x: x['addr']==scope['ip'], clients) + client = next(filtered_client, False) + if client: + scope['state'] = client['state'] + else: + scope['state'] = 'OFF' + scope['ip'] = [scope['ip']] + else: + scope['ip'] = [] + for child in scope['scope']: + scope['ip'] += add_state_to_scopes(child, clients) + return scope['ip'] + + r = g.server.get('/scopes') + scopes = r.json() + r = g.server.get('/clients') + clients = r.json() + add_state_to_scopes(scopes, clients['clients']) + return render_template('scopes.html', scopes=scopes, clients=clients) -- cgit v1.2.3-18-g5258