(request: WSGIRequest)
return JsonResponse({"suggestion": playlist.title, "key": playlist.id})
This method returns a random suggestion from the database.
    Depending on the value of :param playlist:,
    either a previously pushed playlist or song is returned.
This method returns a random suggestion from the database.
    Depending on the value of :param playlist:,
    either a previously pushed playlist or song is returned.
This method returns a random suggestion from the database . Depending on the value of : param playlist : either a previously pushed playlist or song is returned .
def random_suggestion(request: WSGIRequest) -> HttpResponse:
    """This method returns a random suggestion from the database.
    Depending on the value of :param playlist:,
    either a previously pushed playlist or song is returned."""
    suggest_playlist = request.GET["playlist"] == "true"
    if not suggest_playlist:
        if ArchivedSong.objects.count() == 0:
            return HttpResponseBadRequest("No songs to suggest from")
        index = random.randint(0, ArchivedSong.objects.count() - 1)
        song = ArchivedSong.objects.all()[index]
        return JsonResponse({"suggestion": song.displayname(), "key": song.id})

    # exclude radios from suggestions
    remaining_playlists = (
        ArchivedPlaylist.objects.all()
        .exclude(list_id__startswith="RD")
        .exclude(list_id__contains="&list=RD")
    )
    if remaining_playlists.count() == 0:
        return HttpResponseBadRequest("No playlists to suggest from")
    index = random.randint(0, remaining_playlists.count() - 1)
    playlist = remaining_playlists.all()[index]
    return JsonResponse({"suggestion": playlist.title, "key": playlist.id})
def random_suggestion ( request : WSGIRequest ) -> HttpResponse : suggest_playlist = request . GET [ "playlist" ] == "true" if not suggest_playlist : if ArchivedSong . objects . count ( ) == 0 : return HttpResponseBadRequest ( "No songs to suggest from" ) index = random . randint ( 0 , ArchivedSong . objects . count ( ) - 1 ) song = ArchivedSong . objects . all ( ) [ index ] return JsonResponse ( { "suggestion" : song . displayname ( ) , "key" : song . id } ) # exclude radios from suggestions remaining_playlists = ( ArchivedPlaylist . objects . all ( ) . exclude ( list_id__startswith = "RD" ) . exclude ( list_id__contains = "&list=RD" ) ) if remaining_playlists . count ( ) == 0 : return HttpResponseBadRequest ( "No playlists to suggest from" ) index = random . randint ( 0 , remaining_playlists . count ( ) - 1 ) playlist = remaining_playlists . all ( ) [ index ] return JsonResponse ( { "suggestion" : playlist . title , "key" : playlist . id } )