diff options
Diffstat (limited to 'ogcp')
-rw-r--r-- | ogcp/views.py | 22 |
1 files changed, 21 insertions, 1 deletions
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) |