Dashboard fixes: staleness, toner, layout
This commit is contained in:
@@ -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),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user