def is_session_available(req):
    """
    Determine if a session is available. This is similar to a user test,
    but requires access to the user's session, so it cannot be used in the
    user_passes_test decorator.

    Parameters:
        req - The HttpRequest object, with user and session information.
    """
    if req.user.is_superuser or req.user.is_staff:
        return True

    sessions = Session.objects.filter(expire_date__gt=datetime.now())
    count = 0
    for session in sessions:
        try:
            decoded = session.get_decoded()
            if (not req.user.is_anonymous()) and 'activity_time' in decoded and decoded['activity_time'] > datetime.now():
                count += 1
        except SuspiciousOperation:
            logger.debug("SuspiciousOperation caught while checking the last activity time in a user's session. Session key: %s", session.session_key)

    avail = count < settings.CONCURRENT_SESSIONS
    req.session['avail'] = avail

    return avail
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/is_session_available/original