示例#1
0
    def get(self):
        pq = Playlist.all().filter("owner =", users.get_current_user())
        playlists = pq.fetch(1)
        if len(playlists) == 0:
            self.response.out.write("No playlists")
            return

        psq = PlaylistSong.all().filter("playlist =", playlists[0])
        psongs = psq.fetch(100)
        songs = []
        for ps in psongs:
            songs.append(ps.song)

        songsJson = ""
        id = 0
        for song in songs:
            songsJson += '{"name":"%s", "author":1, "album":1, "uri":"%s",' % (song.name, song.uri)
            if song.author:
                author = song.author
            else:
                author = "VA"
            if song.album:
                album = song.album
            else:
                album = "VA"

            songsJson += '"authorName":"%s", "albumName":"%s"}' % (author, album)
            id += 1
            if id != len(songs):
                songsJson += ","

        self.response.out.write('{"songs":[%s]}' % songsJson)
示例#2
0
    def get(self):
        sq = Song.all().filter("uri =", self.request.params["uri"])
        songs = sq.fetch(1)
        if len(songs) == 0:
            self.response.out.write("no song")
            return
        else:
            song = songs[0]

        pq = Playlist.all().filter("owner =", users.get_current_user())
        playlists = pq.fetch(1)
        if len(playlists) == 0:
            pl = Playlist()
            pl.owner = users.get_current_user()
            pl.name = "My"
            pl.status = True
            pl.put()
        else:
            pl = playlists[0]

        ps = PlaylistSong()
        ps.playlist = pl
        ps.song = song
        ps.put()
        self.response.out.write("done")
 def get(self):
     pq = Playlist.all().filter("owner =", users.get_current_user())
     playlists = pq.fetch(1)
     if len(playlists) == 0:
         self.response.out.write('No playlists')
         return
     
     psq = PlaylistSong.all().filter("playlist =", playlists[0])
     psongs = psq.fetch(100)
     songs = []
     for ps in psongs:
         songs.append(ps.song)
     
     songs_json = format_json(songs)
     
     self._print('{"songs":[%s]}' % songs_json)
 def get(self):
     sq = Song.all().filter("uri =", self.request.params['uri'])
     songs = sq.fetch(1)
     if len(songs) == 0:
         self.response.out.write('no song')
         return
     else:
         song = songs[0]
     
     pq = Playlist.all().filter("owner =", users.get_current_user())
     playlists = pq.fetch(1)
     if len(playlists) == 0:
         self.response.out.write('no playlist')
         return
     else:
         pl = playlists[0]
     
     ps = PlaylistSong.all().filter("playlist =", pl)
     for lst in ps:
         if lst.song.uri == song.uri:
             db.delete(lst)
     self._print('done')
 def get(self):
     song = Song.get_by_id(int(self.request.params['id']))
     if not song:
         self.response.out.write('no song')
         return
     
     pq = Playlist.all().filter("owner =", users.get_current_user())
     playlists = pq.fetch(1)
     if len(playlists) == 0:
         pl = Playlist()
         pl.owner = users.get_current_user()
         pl.name = 'My'
         pl.status = True
         pl.put()
     else:
         pl = playlists[0]
     
     ps = PlaylistSong()
     ps.playlist = pl
     ps.song = song
     ps.put()
     self._print('done')