def METHOD_NAME(request):
    if request.method != "POST":
        return HttpResponse(content="ajax user lookup requires HTTP POST", status=405, content_type="text/plain")
    elif "query" not in request.POST:
        return HttpResponse(
            content='use a field named "query" to specify a prefix to filter usernames', content_type="text/plain"
        )
    keyword = request.POST["query"]
    users = (
        get_user_model()
        .objects.filter(Q(username__icontains=keyword))
        .exclude(Q(username="AnonymousUser") | Q(is_active=False))
    )
    if request.user and request.user.is_authenticated and request.user.is_superuser:
        groups = GroupProfile.objects.filter(Q(title__icontains=keyword) | Q(slug__icontains=keyword))
    elif request.user.is_anonymous:
        groups = GroupProfile.objects.filter(Q(title__icontains=keyword) | Q(slug__icontains=keyword)).exclude(
            Q(access="private")
        )
    else:
        groups = GroupProfile.objects.filter(Q(title__icontains=keyword) | Q(slug__icontains=keyword)).exclude(
            Q(access="private") & ~Q(slug__in=request.user.groupmember_set.values_list("group__slug", flat=True))
        )
    json_dict = {
        "users": [({"username": u.username}) for u in users],
        "count": users.count(),
    }
    json_dict["groups"] = [({"name": g.slug, "title": g.title}) for g in groups]
    return HttpResponse(content=json.dumps(json_dict), content_type="text/plain")