summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-07-03 15:07:38 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-07-03 15:48:24 +0200
commitb510d625b2015e62fdd0fe21b7a26519cce193a6 (patch)
treefacc54acacd63175645372fb2ea359e7306d2527
parent9ea8a74c633082ba21640cf65d0aeb532c59d376 (diff)
views: show MAC as lowercase with colon separators
Define a function to format the MAC string for every view in the web. Example of formatted MAC address: aa:bb:cc:dd:ee:aa Show MAC address in client pills in that same format.
-rw-r--r--ogcp/views.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index ab75280..e41e242 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -99,6 +99,9 @@ class ServerErrorCode(Exception):
def normalize_mac(mac):
return mac.replace(':', '').replace('-', '').replace('.', '').lower()
+def prettify_mac(mac):
+ return (':'.join(mac[i:i+2] for i in range(0, 12, 2))).lower()
+
def ogserver_down(view):
flash(_('Cannot talk to ogserver. Is ogserver down?'), category='error')
return redirect(url_for(view))
@@ -494,7 +497,7 @@ def get_client_mac():
resp = server.get('/client/info', payload)
client_info = resp.json()
mac = client_info.get('mac')
- pretty_mac = (':'.join(mac[i:i+2] for i in range(0, 12, 2))).upper()
+ pretty_mac = prettify_mac(mac)
return jsonify(pretty_mac)
@@ -1216,7 +1219,7 @@ def action_client_info():
form.name.render_kw = {'readonly': True}
form.ip.data = db_client['ip']
form.ip.render_kw = {'readonly': True}
- form.mac.data = db_client['mac']
+ form.mac.data = prettify_mac(db_client['mac'])
form.mac.render_kw = {'readonly': True}
form.serial_number.data = db_client['serial_number']
form.serial_number.render_kw = {'readonly': True}
@@ -1340,7 +1343,7 @@ def action_client_update():
form.ip.data = db_client['ip']
form.ip.render_kw = {'readonly': True}
form.name.data = db_client['name']
- form.mac.data = db_client['mac']
+ form.mac.data = prettify_mac(db_client['mac'])
form.serial_number.data = db_client['serial_number']
form.livedir.render_kw = {'readonly': True}
form.remote.data = db_client['remote']
@@ -1590,7 +1593,7 @@ def action_client_add():
available_modes.extend([(mode, mode) for mode in r.json()['modes'] if mode != 'pxe'])
form.boot.choices = list(available_modes)
- form.mac.render_kw = {'placeholder': 'aabbccddeeaa'}
+ form.mac.render_kw = {'placeholder': 'aa:bb:cc:dd:ee:aa'}
r = server.get('/scopes')
if not r: