summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-09-02 14:45:02 +0200
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-09-02 14:45:02 +0200
commit30c5173aeaf700c7b03ad252541a353c47352d29 (patch)
treea9efdb2ef47b23887ccc33f684da76ae77c5e0a6 /ogcp/views.py
parent46b88fff0b73ceae83e2af08a6ba372bb7bf75a4 (diff)
Implement scopes() view function
This function provides the data needed to render the scopes.html template.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py22
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)