parameters: (u)
return_statement: return (count <= 1)
docstring: A test to determine if the user of the application is using a unique
      session. Each user is permitted one unique session (one session in the
      django_session table that has not yet expired). If the user exceeds
      this quota, this test fails, and the user will get bounced to the login
      url.
  
      Parameters:
          u - The user. May be anonymous or registered.
  
      Returns:
          True - the user is an AnonymousUser or the number of sessions open
                 by the user is only 1 (one must be open to make the request)
          False - the user is registered and has more than one open session.
docstring_summary: A test to determine if the user of the application is using a unique
      session. Each user is permitted one unique session (one session in the
      django_session table that has not yet expired). If the user exceeds
      this quota, this test fails, and the user will get bounced to the login
      url.
docstring_tokens: A test to determine if the user of the application is using a unique session . Each user is permitted one unique session ( one session in the django_session table that has not yet expired ) . If the user exceeds this quota this test fails and the user will get bounced to the login url .
function: def using_unique_session(u):
      """
      A test to determine if the user of the application is using a unique
      session. Each user is permitted one unique session (one session in the
      django_session table that has not yet expired). If the user exceeds
      this quota, this test fails, and the user will get bounced to the login
      url.
  
      Parameters:
          u - The user. May be anonymous or registered.
  
      Returns:
          True - the user is an AnonymousUser or the number of sessions open
                 by the user is only 1 (one must be open to make the request)
          False - the user is registered and has more than one open session.
      """
      if u.is_anonymous() or u.is_superuser:
          return True
  
      sessions = Session.objects.all()
      count = 0
      for session in sessions:
          try:
              decoded = session.get_decoded()
  
              if '_auth_user_id' in decoded and decoded['_auth_user_id'] == u.id:
                  if 'activity_time' in decoded and decoded['activity_time'] < datetime.now(
                  ):
                      # delete this session of mine; it is dormant
                      Session.objects.filter(
                          session_key=session.session_key).delete()
                  else:
                      count += 1
          except SuspiciousOperation:
              logger.debug(
                  "SuspiciousOperation caught while checking the number of sessions a user has open. Session key: %s",
                  session.session_key)
  
      # after counting all the open and active sessions, go back through
      # the session list and assign the session count to all web sessions
      # for this user. (do this for inactive sessions, too)
      for session in sessions:
          try:
              decoded = session.get_decoded()
              if '_auth_user_id' in decoded and decoded['_auth_user_id'] == u.id:
                  websession = SessionStore(session_key=session.session_key)
                  websession['count'] = count
                  websession.save()
          except SuspiciousOperation:
              logger.debug(
                  "SuspiciousOperation caught while setting the session count on all user sessions. Session key: %s",
                  session.session_key)
  
      return (count <= 1)
function_tokens: def using_unique_session ( u ) : if u . is_anonymous ( ) or u . is_superuser : return True sessions = Session . objects . all ( ) count = 0 for session in sessions : try : decoded = session . get_decoded ( ) if '_auth_user_id' in decoded and decoded [ '_auth_user_id' ] == u . id : if 'activity_time' in decoded and decoded [ 'activity_time' ] < datetime . now ( ) : # delete this session of mine; it is dormant Session . objects . filter ( session_key = session . session_key ) . delete ( ) else : count += 1 except SuspiciousOperation : logger . debug ( "SuspiciousOperation caught while checking the number of sessions a user has open. Session key: %s" , session . session_key ) # after counting all the open and active sessions, go back through # the session list and assign the session count to all web sessions # for this user. (do this for inactive sessions, too) for session in sessions : try : decoded = session . get_decoded ( ) if '_auth_user_id' in decoded and decoded [ '_auth_user_id' ] == u . id : websession = SessionStore ( session_key = session . session_key ) websession [ 'count' ] = count websession . save ( ) except SuspiciousOperation : logger . debug ( "SuspiciousOperation caught while setting the session count on all user sessions. Session key: %s" , session . session_key ) return ( count <= 1 )