Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use IDs instead of keys, makes shorter URLs

  • Loading branch information...
commit 095762cfb1dbd0a3e6dba364da28e1815f7bb47a 1 parent 0b0af17
Per Thulin authored
Showing with 12 additions and 12 deletions.
  1. +6 −6 playlists.py
  2. +6 −6 test/test_playlists.py
View
12 playlists.py
@@ -10,7 +10,7 @@ class SpecificPlaylistHandler(webapp.RequestHandler):
def get(self):
"""Get playlist"""
playlist_id = self.request.path.split('/')[-1]
- playlist_model = db.get(db.Key(playlist_id))
+ playlist_model = Playlist.get_by_id(int(playlist_id))
youtify_user = get_current_youtify_user()
self.response.headers['Content-Type'] = 'application/json'
@@ -19,21 +19,21 @@ def get(self):
def post(self):
"""Update playlist"""
playlist_id = self.request.path.split('/')[-1]
- playlist_model = db.get(db.Key(playlist_id))
+ playlist_model = Playlist.get_by_id(int(playlist_id))
youtify_user = get_current_youtify_user()
json = self.request.get('json')
if playlist_model.owner.key() == youtify_user.key():
playlist_model.json = json
playlist_model.save()
- self.response.out.write(str(playlist_model.key()))
+ self.response.out.write(str(playlist_model.key().id()))
else:
self.error(403)
def delete(self):
"""Delete playlist"""
playlist_id = self.request.path.split('/')[-1]
- playlist_model = db.get(db.Key(playlist_id))
+ playlist_model = Playlist.get_by_id(int(playlist_id))
youtify_user = get_current_youtify_user()
if playlist_model.owner.key() == youtify_user.key():
@@ -61,11 +61,11 @@ def post(self):
playlist_model.put()
json = simplejson.loads(self.request.get('json'))
- json['remoteId'] = str(playlist_model.key())
+ json['remoteId'] = playlist_model.key().id()
playlist_model.json = simplejson.dumps(json)
playlist_model.save()
- self.response.out.write(str(playlist_model.key()))
+ self.response.out.write(playlist_model.key().id())
def main():
application = webapp.WSGIApplication([
View
12 test/test_playlists.py
@@ -26,7 +26,7 @@ def _post_playlist(self):
handler = PlaylistsHandler()
handler.request = Request({
'REQUEST_METHOD': 'POST',
- 'PATH_INFO': '/playlists',
+ 'PATH_INFO': '/api/playlists',
'wsgi.input': StringIO(form),
'CONTENT_LENGTH': len(form),
'SERVER_NAME': 'hi',
@@ -44,7 +44,7 @@ def test_create_playlist(self):
playlists = [m for m in Playlist.all()]
self.failUnless(len(playlists) == 1)
- self.failUnless(response == str(playlists[0].key()))
+ self.failUnless(response == str(playlists[0].key().id()))
def test_get_playlists(self):
self._post_playlist()
@@ -54,7 +54,7 @@ def test_get_playlists(self):
handler = PlaylistsHandler()
handler.request = Request({
'REQUEST_METHOD': 'GET',
- 'PATH_INFO': '/playlists',
+ 'PATH_INFO': '/api/playlists',
'SERVER_NAME': 'hi',
'SERVER_PORT': '80',
'wsgi.url_scheme': 'http',
@@ -66,7 +66,7 @@ def test_get_playlists(self):
response = simplejson.loads(response)
self.failUnless(response[0]['title'] == 'lopez')
- self.failUnless(response[0]['remoteId'] == str(playlist_model.key()))
+ self.failUnless(response[0]['remoteId'] == playlist_model.key().id())
def test_update_playlists(self):
self._post_playlist()
@@ -87,7 +87,7 @@ def test_update_playlists(self):
handler = SpecificPlaylistHandler()
handler.request = Request({
'REQUEST_METHOD': 'POST',
- 'PATH_INFO': '/playlists/' + str(playlist_model.key()),
+ 'PATH_INFO': '/api/playlists/' + str(playlist_model.key().id()),
'wsgi.input': StringIO(form),
'CONTENT_LENGTH': len(form),
'SERVER_NAME': 'hi',
@@ -98,6 +98,6 @@ def test_update_playlists(self):
handler.response = Response()
handler.post()
- playlist_model = db.get(playlist_model.key())
+ playlist_model = Playlist.get_by_id(1)
json = simplejson.loads(playlist_model.json)
self.failUnless(json['title'] == 'britney')
Please sign in to comment.
Something went wrong with that request. Please try again.