mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
🎨 — Better domains sorting on domain view
This commit is contained in:
parent
9316aa9a79
commit
9df5af7cb4
1 changed files with 14 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
"""Web interface for humans"""
|
||||
from collections import defaultdict
|
||||
from functools import cmp_to_key
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
|
@ -50,7 +51,7 @@ async def get_severity_counts(
|
|||
@route.get("/details")
|
||||
async def read_tasks(request: Request, db: Session = Depends(get_db)):
|
||||
"""Show all tasks and their current state"""
|
||||
tasks = db.query(Task).order_by(Task.domain.desc()).all()
|
||||
tasks = db.query(Task).all()
|
||||
|
||||
results = (
|
||||
db.query(Task, Result)
|
||||
|
@ -71,9 +72,20 @@ async def read_tasks(request: Request, db: Session = Depends(get_db)):
|
|||
def _max_severity(severities):
|
||||
return max(severities, key=SEVERITY_LEVELS.get)
|
||||
|
||||
def _cmp_domains(a, b):
|
||||
if SEVERITY_LEVELS[a[1]] < SEVERITY_LEVELS[b[1]]:
|
||||
return 1
|
||||
if SEVERITY_LEVELS[a[1]] > SEVERITY_LEVELS[b[1]]:
|
||||
return -1
|
||||
if a[0] > b[0]:
|
||||
return 1
|
||||
if a[0] < b[0]:
|
||||
return -1
|
||||
return 0
|
||||
|
||||
domains = [(key, _max_severity(value)) for key, value in domains_severities.items()]
|
||||
last_checks = {key: max(value) for key, value in domains_last_checks.items()}
|
||||
domains.sort(key=lambda x: SEVERITY_LEVELS[x[1]], reverse=True)
|
||||
domains.sort(key=cmp_to_key(_cmp_domains))
|
||||
|
||||
agents = db.query(Result.agent_id).distinct().all()
|
||||
|
||||
|
|
Loading…
Reference in a new issue