def feed(request): songs_played = PlayHistory.objects.all().order_by('created_at').reverse()[0:50] tracks = [] for play in songs_played: lastfm_track = play.song.lastfm_track tracks.append({'name':_encode(lastfm_track.name), 'artist':_encode(lastfm_track.artist),'created_at':play.created_at}) tracks = ordered_unique(tracks) playlist_title = 'recently listened to on odosloop' return direct_to_template(request, 'includes/playlist.html', {'playlist_id':'feed','playlist_title':playlist_title, 'lastfm_tracks':tracks})
def get_tracks(doc): tracks = track_path(doc) lastfm_tracks = [] for track in tracks: artist = track.find('artist').text_content() name = track.find('name').text_content() lastfm_tracks.append({'name':_encode(name),'artist':_encode(artist)}) lastfm_tracks = ordered_unique(lastfm_tracks) return lastfm_tracks
def anonymous(request): songs_played = request.session.get('playhistory',[]) tracks = [] for song in songs_played: tracks.append({'name':song['name'],'artist':song['artist']}) # create a dummy list of playlist user_playlists = [ {'user':{'username':'******'}, 'playlist':{'name':'Favorites'}}] tracks = ordered_unique(tracks) return direct_to_template(request, 'accounts/profile.html', {'playlist_id':'feed', 'playlist_title':'scrobbled on odosloop','lastfm_tracks':tracks, 'user_playlists':user_playlists})
def profile(request, username=None): """ For now just look the user up in last.fm and display their info. """ musiphile = Musiphile.objects.get(id=request.user.id) songs_played = PlayHistory.objects.filter(musiphile=musiphile).order_by('created_at').reverse()[0:50] tracks = [] for play in songs_played: lastfm_track = play.song.lastfm_track tracks.append({'name':lastfm_track.name,'artist':lastfm_track.artist,'created_at':play.created_at}) tracks = ordered_unique(tracks) user_playlists = PlaylistUser.objects.filter(user=musiphile) return direct_to_template(request, 'accounts/profile.html', {'playlist_id':'feed', 'playlist_title':'scrobbled on odosloop', 'lastfm_tracks': tracks, 'user_playlists':user_playlists, 'username':username})