mirror of https://git.48k.eu/ogcp
Implement scopes() view function
This function provides the data needed to render the scopes.html template.multi-ogserver
parent
46b88fff0b
commit
30c5173aea
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue