(request: WSGIRequest)
return JsonResponse(suggestions, safe=False)
Returns a list of all subdirectories for the given path.
Returns a list of all subdirectories for the given path.
Returns a list of all subdirectories for the given path .
def list_subdirectories(request: WSGIRequest) -> HttpResponse:
    """Returns a list of all subdirectories for the given path."""
    path = request.GET.get("path")
    if path is None:
        return HttpResponseBadRequest("path was not supplied.")
    basedir, subdirpart = os.path.split(path)
    if path == "":
        suggestions = ["/"]
    elif os.path.isdir(basedir):
        suggestions = [
            os.path.join(basedir, subdir + "/")
            for subdir in next(os.walk(basedir))[1]
            if subdir.lower().startswith(subdirpart.lower())
        ]
        suggestions.sort()
    else:
        suggestions = ["not a valid directory"]
    if not suggestions:
        suggestions = ["not a valid directory"]
    return JsonResponse(suggestions, safe=False)
def list_subdirectories ( request : WSGIRequest ) -> HttpResponse : path = request . GET . get ( "path" ) if path is None : return HttpResponseBadRequest ( "path was not supplied." ) basedir , subdirpart = os . path . split ( path ) if path == "" : suggestions = [ "/" ] elif os . path . isdir ( basedir ) : suggestions = [ os . path . join ( basedir , subdir + "/" ) for subdir in next ( os . walk ( basedir ) ) [ 1 ] if subdir . lower ( ) . startswith ( subdirpart . lower ( ) ) ] suggestions . sort ( ) else : suggestions = [ "not a valid directory" ] if not suggestions : suggestions = [ "not a valid directory" ] return JsonResponse ( suggestions , safe = False )