def logout(request):
    """
    Removes the authenticated user's ID from the request and flushes their
    session data.
    """
    user = getattr(request, 'user', None)
    if hasattr(user, 'is_authenticated') and not user.is_authenticated():
        return False
    language = request.session.get('django_language')
    request.session.flush()
    if language is not None:
        request.session['django_language'] = language
    if hasattr(request, 'user'):
        from .models import AnonymousUser
        request.user = AnonymousUser()
    return True
