utils.py 526 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from datetime import datetime, timedelta
from django.utils.timezone import make_aware

from base_app.models import User


def get_today_as_datetime():
    now = datetime.now()
    today = now.replace(hour=0, minute=0, second=0, microsecond=1)
    return make_aware(today)


def get_daily_connections() -> int:
    today = get_today_as_datetime()
    yesterday = today - timedelta(days=1)
    nb_connections = User.objects.filter(
        last_login__gte=yesterday, last_login__lt=today
    ).count()
    return nb_connections