mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
Merge branch 'fix-domains-sorting' into 'main'
🐛 — Fix domains sorting on domains view
See merge request framasoft/framaspace/argos!26
This commit is contained in:
commit
b8ffca069d
2 changed files with 22 additions and 4 deletions
|
@ -435,6 +435,7 @@ disable=raw-checker-failed,
|
|||
use-implicit-booleaness-not-comparison-to-zero,
|
||||
fixme,
|
||||
too-few-public-methods,
|
||||
too-many-locals,
|
||||
unused-argument,
|
||||
import-outside-toplevel,
|
||||
no-self-argument,
|
||||
|
|
|
@ -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
|
||||
|
@ -15,6 +16,12 @@ from argos.server.routes.dependencies import get_config, get_db
|
|||
route = APIRouter()
|
||||
|
||||
templates = Jinja2Templates(directory="argos/server/templates")
|
||||
SEVERITY_LEVELS = {
|
||||
"ok": 1,
|
||||
"warning": 2,
|
||||
"critical": 3,
|
||||
"to-process": 4
|
||||
}
|
||||
|
||||
|
||||
@route.get("/")
|
||||
|
@ -44,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).all()
|
||||
tasks = db.query(Task).all()
|
||||
|
||||
results = (
|
||||
db.query(Task, Result)
|
||||
|
@ -63,12 +70,22 @@ async def read_tasks(request: Request, db: Session = Depends(get_db)):
|
|||
domains_last_checks[domain].append(result.submitted_at)
|
||||
|
||||
def _max_severity(severities):
|
||||
severity_level = {"ok": 1, "warning": 2, "critical": 3, "to-process": 4}
|
||||
return max(severities, key=severity_level.get)
|
||||
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: x[1])
|
||||
domains.sort(key=cmp_to_key(_cmp_domains))
|
||||
|
||||
agents = db.query(Result.agent_id).distinct().all()
|
||||
|
||||
|
|
Loading…
Reference in a new issue