Skip to content

Commit

Permalink
fix to sorting by online
Browse files Browse the repository at this point in the history
  • Loading branch information
bryangerlach committed Mar 30, 2024
1 parent 2900ea3 commit 363a0ee
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/views_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,18 @@ def get_all_info():

for k, v in devices.items():
devices[k]['status'] = _('Online') if (now-datetime.datetime.strptime(v['update_time'], '%Y-%m-%d %H:%M')).seconds <=120 else _('Offline')
return [v for k,v in sorted(devices.items(), key=lambda item: item['status'])]
sorted_devices = sorted(devices.items(), key=custom_sort)
new_ordered_dict = {}
for key, device in sorted_devices:
new_ordered_dict[key] = device
return [v for k,v in new_ordered_dict.items()]

def custom_sort(item):
status = item[1]['status']
if status == 'Online':
return 1
else:
return 0

@login_required(login_url='/api/user_action?action=login')
def work(request):
Expand Down

0 comments on commit 363a0ee

Please sign in to comment.