def setCurrentCalcNext( context = dict() ):
    global p
    global g_p
    global g_7digital_cur
    global g_7digital_nexts
    global g_song_features

    g_7digital_nexts      = MX_traverse.pickNextSongsWrapped( g_7digital_cur );
    g_song_features       = MX_traverse.get_song_by_7digital( g_7digital_cur )
    g_nexts_features      = [MX_traverse.get_song_by_7digital( x ) for x in g_7digital_nexts[0]]
    song_url              = MX_traverse.get_song_url( g_7digital_cur )
    if g_p['save_playlist']:
        g_p['playlist_file'] = g_p['playlist_pref'] + time.strftime("%Y%m%d-%H%M%S") + '.csv'
        MX_traverse.addSongToPlaylist( g_p['playlist_file'], g_song_features, song_url )
    
    context['song_url']    = song_url+'#t='+str(g_p['play_interval'][0])+","+str(g_p['play_interval'][1])
    context['id_7digital'] = g_7digital_cur
    context['title']       = g_song_features[p['invkey']['title']]
    context['artist']      = g_song_features[p['invkey']['artist_name']]

    for i in range(len(g_nexts_features)):
        context['n'+str(i)+'_id_7digital'] = g_nexts_features[i][p['invkey']['track_7digitalid']]
        context['n'+str(i)+'_title']       = g_nexts_features[i][p['invkey']['title']]
        context['n'+str(i)+'_artist']      = g_nexts_features[i][p['invkey']['artist_name']]

    return context
def bandura():
    global p
    global g_p
    global g_7digital_cur
    global g_7digital_nexts  
    global g_song_features
    global g_nexts_features
    global g_next_choice

    print "bandura"
    context = packContext( 0 );

    if 1: #request.method == "POST":
        if request.method == "POST":
            print "'bandura' called by POST"
            updateParamsFromSite( request.form )

        context = packContext( 0 ); 

        if g_7digital_nexts:
            print "cur song id exists"
            print g_7digital_nexts
            g_7digital_cur   = g_7digital_nexts[0][g_next_choice]
            g_song_features  = g_nexts_features[g_next_choice]
            song_url         = OAuth.get_song_url(g_7digital_cur);
            g_7digital_nexts = MX_traverse.pickNextSongsWrapped( g_7digital_cur );
            g_nexts_features = [MX_traverse.get_song_by_7digital( x ) for x in g_7digital_nexts[0]]
            if g_p['save_playlist']:
                MX_traverse.addSongToPlaylist( g_p['playlist_file'], g_song_features, song_url )

            context['song_url']     = song_url+"#t="+str(g_p['play_interval'][0])+","+str(g_p['play_interval'][1])
            context['id_7digital']  = g_7digital_cur
            context['title']        = g_song_features[p['invkey']['title']]
            context['artist']       = g_song_features[p['invkey']['artist_name']]
                        
            for i in range(len(g_nexts_features)):
                context['n'+str(i)+'_id_7digital'] = g_nexts_features[i][p['invkey']['track_7digitalid']]
                context['n'+str(i)+'_title']       = g_nexts_features[i][p['invkey']['title']]
                context['n'+str(i)+'_artist']      = g_nexts_features[i][p['invkey']['artist_name']]
        else:
            print "cur song id does NOT exists"
    else:
        print "'bandura' called by GET"
    print "rendering bandura"
    return render_template("bandura.html", **context);