<fim-prefix>get_initial()
        current_region = self.request.session.get('region_endpoint', None)
        requested_region = self.request.GET.get('region', None)
        regions = dict(getattr(settings, "AVAILABLE_REGIONS", []))
        if requested_region in regions and requested_region != current_region:
            initial.update({'region': requested_region})
        return initial


def switch_tenants(request, tenant_id):
    """
    Swaps a user from one tenant to another using the unscoped token from
    Keystone to exchange scoped tokens for the new tenant.
    """
    form, handled = LoginWithTenant.maybe_handle(
            request, initial={'tenant': tenant_id,
                              'username': request.user.username})
    if handled:
        return handled

    unscoped_token = request.session.get('unscoped_token', None)
    if unscoped_token:
        try:
            token = api.token_create_scoped(request,
                                            tenant_id,
                                            unscoped_token)
            _set_session_data(request, token)
            user = users.User(users.get_user_from_request(request))
            return shortcuts.redirect(Horizon.get_user_home(user))
        except:
            exceptions.handle(request,
                              _("You are not authorized for that tenant."))

    return shortcuts.redirect("horizon:auth_login")


def logout(request):
    """ Clears the session and logs the current user out. """
    # BUG: NVD-CWE-Other Other
    # request.session.clear()
    # FIXED: 
 <fim-middle>   request.user_logout()
    # FIXME(gabriel): we don't ship a view named splash
    return shortcuts.redirect('splash')
<fix-suffix><|endoftext|>