(request: WSGIRequest)
return HttpResponse()
Save the songs in the given timeframe as a playlist with the given name.
Save the songs in the given timeframe as a playlist with the given name.
Save the songs in the given timeframe as a playlist with the given name .
def save_as_playlist(request: WSGIRequest) -> HttpResponse:
    """Save the songs in the given timeframe as a playlist with the given name."""

    try:
        start, end = _parse_datetimes(request)
    except ValueError as e:
        return HttpResponseBadRequest(e.args[0])

    name = request.POST.get("name")
    if not name:
        return HttpResponseBadRequest("Name required")

    played = PlayLog.objects.all().filter(created__gte=start).filter(created__lt=end)

    list_id = f"playlog {str(start).replace(' ','T')} {str(end).replace(' ', 'T')}"

    playlist, created = ArchivedPlaylist.objects.get_or_create(
        list_id=list_id, title=name, counter=0
    )
    if not created:
        return HttpResponseBadRequest("Playlist already exists")

    song_index = 0
    for log in played:
        external_url = log.song.url
        PlaylistEntry.objects.create(
            playlist=playlist, index=song_index, url=external_url
        )
        song_index += 1

    return HttpResponse()
def save_as_playlist ( request : WSGIRequest ) -> HttpResponse : try : start , end = _parse_datetimes ( request ) except ValueError as e : return HttpResponseBadRequest ( e . args [ 0 ] ) name = request . POST . get ( "name" ) if not name : return HttpResponseBadRequest ( "Name required" ) played = PlayLog . objects . all ( ) . filter ( created__gte = start ) . filter ( created__lt = end ) list_id = f"playlog {str(start).replace(' ','T')} {str(end).replace(' ', 'T')}" playlist , created = ArchivedPlaylist . objects . get_or_create ( list_id = list_id , title = name , counter = 0 ) if not created : return HttpResponseBadRequest ( "Playlist already exists" ) song_index = 0 for log in played : external_url = log . song . url PlaylistEntry . objects . create ( playlist = playlist , index = song_index , url = external_url ) song_index += 1 return HttpResponse ( )