From 1981f73212617cd0b422d79e42af25a655437302 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 5 Mar 2025 10:02:42 +0100 Subject: [PATCH] feat: expose active sessions in stats endpoint --- umap/tests/test_views.py | 2 ++ umap/views.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/umap/tests/test_views.py b/umap/tests/test_views.py index a0de69f8..83093daf 100644 --- a/umap/tests/test_views.py +++ b/umap/tests/test_views.py @@ -183,6 +183,7 @@ def test_stats_empty(client): "maps_count": 0, "users_active_last_week_count": 0, "users_count": 0, + "active_sessions": 0, "version": VERSION, } @@ -199,6 +200,7 @@ def test_stats_basic(client, map, datalayer, user2): "maps_count": 1, "users_active_last_week_count": 1, "users_count": 2, + "active_sessions": 0, "version": VERSION, } diff --git a/umap/views.py b/umap/views.py index de3f154a..2f70202a 100644 --- a/umap/views.py +++ b/umap/views.py @@ -19,6 +19,7 @@ from django.contrib.auth import BACKEND_SESSION_KEY, get_user_model from django.contrib.auth import logout as do_logout from django.contrib.gis.measure import D from django.contrib.postgres.search import SearchQuery, SearchVector +from django.contrib.sessions.models import Session from django.contrib.staticfiles.storage import staticfiles_storage from django.core.exceptions import PermissionDenied from django.core.mail import send_mail @@ -1382,6 +1383,9 @@ def stats(request): "users_active_last_week_count": User.objects.filter( last_login__gt=last_week ).count(), + "active_sessions": Session.objects.filter( + expire_date__gt=datetime.utcnow() + ).count(), } )