Example #1
0
    def post(self):
        if not users.get_current_user():
            self.redirect(users.create_login_url(self.request.uri))
            return

        neededFields = ("uri", "songName", "authorName", "albumName", "albumYear")
        errors = {}
        for field in neededFields:
            if field not in self.request.params or self.request.params[field] == "":
                errors[field] = 'Please fill field "' + field + '"'

        if len(errors) == 0:
            song = Song()
            song.owner = users.get_current_user()
            song.uri = self.request.params["uri"]
            song.name = self.request.params["songName"]
            song.author = self.request.params["authorName"]
            song.album = self.request.params["albumName"]
            song.albumYear = self.request.params["albumYear"]
            song.status = True
            song.put()

            self.response.out.write
            path = os.path.join(os.path.dirname(__file__), "../templates/add.html")

            if "isAlbum" not in self.request.params or self.request.params["isAlbum"] != "on":
                params = {"uri": "", "songName": "", "authorName": "", "albumName": "", "albumYear": ""}
            else:
                params = self.request.params

            self.response.out.write(template.render(path, {"params": params}))
        else:
            self.response.out.write(repr(errors))
            self.response.out.write(repr(self.request.params))
Example #2
0
 def post(self):
     if not users.get_current_user():
         self._print('{"status":"0", "message":"Not logged"}')
     
     errors = False
     params = {}
     for field in ['song_name', 'author_name', 'album_name', 'album_year', 'song_uri']:
         if self.request.params.get(field):
             params[field] = self.request.params.get(field)
         else:
             errors = True
     
     if not errors:
         song = Song()
         song.owner = users.get_current_user()
         song.uri = params['song_uri']
         song.name = params['song_name']
         song.author = params['author_name']
         song.album = params['album_name']
         song.albumYear = params['album_year']
         song.status = True;
         song.put()
     
         self._print('{"status":"1", "message":"Added successully"}')
     else:
         self._print('{"status":"0", "message":"Not all fields are filled"}')
Example #3
0
 def get(self, authorName):
     authorName = re.sub('_', ' ', authorName)
     
     #sq = Song.gql("WHERE author = '%s' ORDER BY date ASC" % authorName)
     sq = Song.all().filter("author =", authorName).order("date")
     songs = sq.fetch(100)
     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)
Example #4
0
 def get(self):
     sq = Song.all().filter("owner =", users.get_current_user())
     songs = sq.fetch(100)
     
     songs_json = format_json(songs)
     
     self._print('{"songs":[%s]}' % songs_json)
Example #5
0
 def get(self):
     songsQuery = Song.all().order('-date')
     songs = songsQuery.fetch(100)
 
     songs_json = format_json(songs)
 
     self._print('{"songs":[%s]}' % songs_json)
Example #6
0
    def get(self):

        songsQuery = Song.all().order("-date")
        songs = songsQuery.fetch(100)

        artists = []
        artistsHtml = ""
        for song in songs:
            if song.author and song.author not in artists:
                artists.append(song.author)
                arUrl = re.sub(" ", "_", song.author)
                artistsHtml += "<li>"
                artistsHtml += '<a href="#artists/' + arUrl + '" '
                artistsHtml += " onClick=\"Player.load('/api/songs/author/" + arUrl + ".json');\">"
                artistsHtml += song.author
                artistsHtml += "</a>"
                artistsHtml += "</li>"

        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = "Logout"
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = "Login"

        template_values = {
            "user": users.get_current_user(),
            "url": url,
            "url_linktext": url_linktext,
            "artists": artistsHtml,
        }

        path = os.path.join(os.path.dirname(__file__), "../templates/restyled/index.html")
        self.response.out.write(template.render(path, template_values))
Example #7
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")
Example #8
0
 def get(self, authorName):
     authorName = re.sub('_', ' ', authorName)
     
     #sq = Song.gql("WHERE author = '%s' ORDER BY date ASC" % authorName)
     sq = Song.all().filter("author =", authorName).order("date")
     songs = sq.fetch(100)
     
     songs_json = format_json(songs)
     
     self._print('{"songs":[%s]}' % songs_json)
Example #9
0
    def post(self):
        author = self.request.params.get("authorName")
        albumName = self.request.params.get("albumName")
        albumYear = self.request.params.get("albumYear")

        for param in self.request.params:
            if "songName_" == param[0:9]:
                self.response.out.write("<br />%s" % param[9 : len(param)])
                try:
                    name = self.request.params[param]
                    uri = "http://www.ex.ua/get/" + param[9 : len(param)]
                    song = Song()
                    song.owner = users.get_current_user()
                    song.uri = uri
                    song.name = name
                    song.author = author
                    song.album = albumName
                    song.albumYear = albumYear
                    song.status = True
                    song.put()
                except Exception, e:
                    handleError(e)
Example #10
0
 def get(self):
     sq = Song.all().filter("owner =", users.get_current_user())
     songs = sq.fetch(100)
     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)
 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')
Example #13
0
 def get(self):
   songsQuery = Song.all().order('-date')
   songs = songsQuery.fetch(100)
   
   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)
Example #14
0
 def get(self, author_name):
     author_name = re.sub('_', ' ', author_name)
     
     sq = Song.all().filter("author =", author_name).order("date")
     
     self._print('{"songs":[%s]}' % format_json(sq.fetch(100)))