Ejemplo n.º 1
0
def get_playlist(request, playlist_code):
    if 'demo' in request.session or 'demo' in request.GET:
        return redirect('/')
    try:
        poweruser, result = get_all_data(request)
    except NonAuthenticatedException as e:
        logger.debug(e.message)
        return (e.destination)

    activity_type = result["activity_type"]
    activity_type_name = result["activity_type_name"]

    result["playlist_link"] = ""
    if "activity" in playlist_code:
        result[
            "playlist_link"], playlist_name, playlist_id = create_activity_playlist(
                playlist_code)
    elif "global" in playlist_code:
        result[
            "playlist_link"], playlist_name, playlist_id = create_global_playlist(
                playlist_code, activity_type, activity_type_name)
    elif "user" in playlist_code:
        result[
            "playlist_link"], playlist_name, playlist_id = create_user_playlist(
                playlist_code, poweruser, activity_type, activity_type_name)

    return render(request, "get_playlist.html", result)
Ejemplo n.º 2
0
def delete_account(request):
    if request.method != 'DELETE':
        return JsonResponse({})
    if 'demo' in request.session or 'demo' in request.GET:
        return redirect('/')
    try:
        poweruser, result = get_all_data(request)
    except NonAuthenticatedException as e:
        logger.debug(e.message)
        return (e.destination)

    if poweruser.athlete:
        poweruser.athlete.delete()
    if poweruser.listener:
        poweruser.listener.delete()
    if poweruser.listener_spotify:
        poweruser.listener_spotify.delete()
    poweruser.delete()
    return JsonResponse({})
Ejemplo n.º 3
0
def remove_lastfm(request):
    if 'demo' in request.session or 'demo' in request.GET:
        return demo(request)
    try:
        poweruser, result = get_all_data(request)
    except NonAuthenticatedException as e:
        logger.debug(e.message)
        return (e.destination)

    if not poweruser.listener:
        return redirect('/settings/')

    if 'lastfm_token' in request.session:
        del request.session['lastfm_token']
    if 'lastfm_key' in request.session:
        del request.session['lastfm_key']
    if 'lastfm_username' in request.session:
        del request.session['lastfm_username']

    poweruser.listener.delete()

    return redirect('/settings/')
Ejemplo n.º 4
0
def remove_spotify(request):
    if 'demo' in request.session or 'demo' in request.GET:
        return redirect('/')
    try:
        poweruser, result = get_all_data(request)
    except NonAuthenticatedException as e:
        logger.debug(e.message)
        return (e.destination)

    if not poweruser.listener_spotify:
        return redirect('/settings/')

    if 'spotify_token' in request.session:
        del request.session['spotify_token']
    if 'spotify_code' in request.session:
        del request.session['spotify_code']
    if 'spotify_refresh_token' in request.session:
        del request.session['spotify_refresh_token']

    poweruser.listener_spotify.delete()

    return redirect('/settings/')
Ejemplo n.º 5
0
def get_playlists(request):
    if 'demo' in request.session or 'demo' in request.GET:
        return redirect('/')
    try:
        poweruser, result = get_all_data(request)
    except NonAuthenticatedException as e:
        logger.debug(e.message)
        return (e.destination)

    activity_type = result["activity_type"]
    activity_type_name = result["activity_type_name"]

    playlist_codes = [
        "effortly:user:me:top:score", "effortly:user:me:top:bpm:175",
        "effortly:user:me:top:speed", "effortly:user:me:top:cadence",
        "effortly:user:me:missed:score", "effortly:global:top:score",
        "effortly:global:top:bpm:175", "effortly:global:top:speed",
        "effortly:global:top:cadence"
    ]
    result["playlists"] = []
    for playlist_code in playlist_codes:

        playlist = {}
        if "activity" in playlist_code:
            playlist["link"], playlist["name"], playlist[
                "id"] = create_activity_playlist(playlist_code)
        elif "global" in playlist_code:
            playlist["link"], playlist["name"], playlist[
                "id"] = create_global_playlist(playlist_code, activity_type,
                                               activity_type_name)
        elif "user" in playlist_code:
            playlist["link"], playlist["name"], playlist[
                "id"] = create_user_playlist(playlist_code, poweruser,
                                             activity_type, activity_type_name)
        result["playlists"].append(playlist)

    return render(request, "playlists.html", result)
Ejemplo n.º 6
0
def setting(request):
    if 'demo' in request.session or 'demo' in request.GET:
        return redirect('/')
    try:
        poweruser, result = get_all_data(request)
    except NonAuthenticatedException as e:
        logger.debug(e.message)
        return (e.destination)

    if request.method == "POST":
        athlete = poweruser.athlete
        f = SettingForm(request.POST, instance=athlete)
        f.save()

    if not poweruser.listener:
        result['lastfm_authorize_url'] = lastfm_get_auth_url()

    if not poweruser.listener_spotify:
        result['spotify_authorize_url'] = spotify_get_auth_url()

    result['title'] = 'Settings'
    result['form'] = SettingForm(instance=poweruser.athlete)

    return render(request, 'settings.html', result)