From b510d625b2015e62fdd0fe21b7a26519cce193a6 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Wed, 3 Jul 2024 15:07:38 +0200 Subject: 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. --- ogcp/views.py | 11 +++++++---- 1 file 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: -- cgit v1.2.3-18-g5258