Dashboard fixes: staleness, toner, layout

This commit is contained in:
2026-08-11 14:45:29 -04:00
parent 3b37603691
commit 9ae9879b90
7 changed files with 188 additions and 37 deletions

View File

@@ -1395,6 +1395,18 @@ def delete_model_supply(modelsupplyid: int):
return success_response(message='Supply deleted')
def _shortsupplyname(name):
"""'Black Toner Level' -> 'Black'. The card has one line per printer, and
the words Toner and Level carry no information when every row is a toner
level."""
text = (name or 'supply').strip()
for noise in (' Cartridge Level', ' Toner Level', ' Level', ' Cartridge'):
if text.endswith(noise):
text = text[:-len(noise)]
break
return text or 'supply'
@printers_asset_bp.route('/dashboard/supplies', methods=['GET'])
@jwt_required()
@require_permission('printers.view')
@@ -1426,9 +1438,11 @@ def dashboard_supplies():
'printername': printer['printername'] or printer['assetnumber'],
'location': printer['location'],
'status': 'critical' if criticals else 'low',
# 'remaining' is the percent left. There is no 'percent' key -
# reading one rendered every cartridge as "None%" on the board.
'supplies': ', '.join(
'{} {}%'.format(s.get('name') or s.get('type') or 'supply',
s.get('percent'))
'{} {}%'.format(_shortsupplyname(s.get('name')),
s.get('remaining'))
for s in worst),
'iscritical': bool(criticals),
})