Implement scopes() view function

This function provides the data needed to render the scopes.html
template.
multi-ogserver
Roberto Hueso Gómez 2020-09-02 14:45:02 +02:00
parent 46b88fff0b
commit 30c5173aea
1 changed files with 21 additions and 1 deletions

View File

@ -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)