code: def logout(self, all_session=False):
          
          # initialize the counter of the number of destroyed sesisons
          session_nb = 0
          # save the current user username before flushing the session
          username = self.request.session.get("username")
          if username:
              if all_session:
                  logger.info("Logging out user %s from all sessions." % username)
              else:
                  logger.info("Logging out user %s." % username)
          users = []
          # try to get the user from the current session
          try:
              users.append(
                  models.User.objects.get(
                      username=username,
                      session_key=self.request.session.session_key
                  )
              )
          except models.User.DoesNotExist:
              # if user not found in database, flush the session anyway
              self.request.session.flush()
  
          # If all_session is set, search all of the user sessions
          if all_session:
              users.extend(
                  models.User.objects.filter(
                      username=username
                  ).exclude(
                      session_key=self.request.session.session_key
                  )
              )
  
          # Iterate over all user sessions that have to be logged out
          for user in users:
              # get the user session
              session = SessionStore(session_key=user.session_key)
              # flush the session
              session.flush()
              # send SLO requests
              user.logout(self.request)
              # delete the user
              user.delete()
              # increment the destroyed session counter
              session_nb += 1
          if username:
              logger.info("User %s logged out" % username)
          return session_nb
docs: effectively destroy a CAS session
  
              :param boolean all_session: If ``True`` destroy all the user sessions, otherwise
                  destroy the current user session.
              :return: The number of destroyed sessions
              :rtype: int