def post (self, request): #Get in an array the models of all the songs songmodels = database.get_songs("", request.DATA["keyword"]) if songmodels == None: return Response(status=status.HTTP_404_NOT_FOUND) #Users output looks: #[{'song':song_id, 'link':{'rel':'self','href'=:'http://tab_archive/artists/artist_id/song_id'}}, #{{'song':song_id, 'link':{'rel':'self','href'=:'http://tab_archive/artists/artist_id/song_id'}}] songs = {} songlist = [] for songmodel in songmodels: _artistid = songmodel[0] _songid = songmodel[1] _songurl = "http://localhost:8000/tab_archive/artists/%s/%s" %(_artistid ,_songid) _songurl = reverse("song", (_artistid, _songid,), request=request) song = {"song":{}, "artist":{}} song["song"]['song_id'] = _songid song["artist"]['artist_id'] = _artistid _artisturl = reverse("artist", (_artistid,), request=request) song["artist"]['link'] = {'rel':'self', 'href':_artisturl} song["song"]['link'] = {'rel':'self', 'href':_songurl} songlist.append(song) songs["songs"] = songlist response = Response(songlist, status=status.HTTP_200_OK) return response
def get (self, request, artist_id): ''' Get songs by artist. ''' #Get in an array the models of all the tablatures from songs of artist songmodels = database.get_songs(artist_id, None) if songmodels == None: return Response(status=status.HTTP_404_NOT_FOUND) #Serialize each one of the tablatures. An array of tablatures looks like: #[{'song_id':song_id, 'link':{'rel':'self','href'=:'http://tab_archive/artists/artist_id/song_id'}}, #{'song_id':song_id, 'link':{'rel':'self','href'=:'http://tab_archive/artists/artist_id/song_id'}}] songs = [] for songmodel in songmodels: _artistid = songmodel[0] _songid = songmodel[1] _songurl = "http://localhost:8000/tab_archive/artists/"+_artistid + "/" +_songid _songurl = reverse("song", (_artistid,_songid), request=request) song = {} song['song_id'] = _songid song['link'] = {'rel':'self', 'href':_songurl} songs.append(song) response = Response(songs, status=status.HTTP_200_OK) return response