portal: more home cards
This commit is contained in:
parent
3d280f391e
commit
f417d263f3
2 changed files with 101 additions and 27 deletions
|
@ -5,6 +5,7 @@ from sqlalchemy import desc, or_
|
|||
|
||||
from app.models.activity import Activity
|
||||
from app.models.alarms import Alarm
|
||||
from app.models.bridges import Bridge
|
||||
from app.models.mirrors import Origin, Proxy
|
||||
from app.models.base import Group
|
||||
from app.portal.list import NewMirrorListForm
|
||||
|
@ -48,6 +49,16 @@ def format_datetime(s: datetime) -> str:
|
|||
return s.strftime("%a, %d %b %Y %H:%M:%S")
|
||||
|
||||
|
||||
def total_origins_blocked():
|
||||
count = 0
|
||||
for o in Origin.query.filter(Origin.destroyed == None).all():
|
||||
for a in o.alarms:
|
||||
if a.alarm_type.startswith("ooni"):
|
||||
if a.alarm_state == AlarmState.WARNING:
|
||||
count += 1
|
||||
break
|
||||
return count
|
||||
|
||||
@portal.route("/")
|
||||
def portal_home():
|
||||
groups = Group.query.order_by(Group.group_name).all()
|
||||
|
@ -60,9 +71,17 @@ def portal_home():
|
|||
s: len(Alarm.query.filter(Alarm.alarm_state == s.upper(), Alarm.last_updated > (now - timedelta(days=1))).all())
|
||||
for s in ["critical", "warning", "ok", "unknown"]
|
||||
}
|
||||
br_last = {
|
||||
d: len(Bridge.query.filter(Bridge.deprecated > (now - timedelta(days=d))).all())
|
||||
for d in [1, 3, 7]
|
||||
}
|
||||
activity = Activity.query.filter(Activity.added > (now - timedelta(days=2))).order_by(desc(Activity.added)).all()
|
||||
onionified = len([o for o in Origin.query.filter(Origin.destroyed == None).all() if o.onion() != None])
|
||||
ooni_blocked = total_origins_blocked()
|
||||
total_origins = len(Origin.query.filter(Origin.destroyed == None).all())
|
||||
return render_template("home.html.j2", section="home", groups=groups, last24=last24, last72=last72,
|
||||
lastweek=lastweek, proxies=proxies, **alarms, activity=activity)
|
||||
lastweek=lastweek, proxies=proxies, **alarms, activity=activity, total_origins=total_origins,
|
||||
onionified=onionified, br_last=br_last, ooni_blocked=ooni_blocked)
|
||||
|
||||
|
||||
@portal.route("/search")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue