Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added robots.txt + static url, added single track sharing, optimized …

…sorting storing and some smaller overall improvements
  • Loading branch information...
commit cbb6d63c9dac1fa0a9f7617072ce1d7da4bd8da4 1 parent 96b371a
Henrik Berggren authored
View
4 app.yaml
@@ -19,3 +19,7 @@ handlers:
- url: /favicon.ico
static_files: images/favicon.ico
upload: images/favicon.ico
+
+- url: /robots.txt
+ static_files: robots.txt
+ upload: robots.txt
View
25 models.py
@@ -6,7 +6,7 @@
class User(db.Model):
google_user = db.UserProperty(required=True)
date_created = db.DateTimeProperty(auto_now_add=True)
- nickname = db.StringProperty(required=True)
+ nickname = db.TextProperty(required=True)
def playlists(self):
return (x for x in self.library_set.order("position"))
@@ -19,14 +19,20 @@ def has_playlist(self, playlist):
def re_index_playlists(self):
i = 0
+ entities_to_update = []
for p in self.playlists():
p.position = i
- p.put()
+ entities_to_update.append(p)
i+=1
-
+ db.put(entities_to_update)
+
def last_lib_position(self):
- q = db.GqlQuery("SELECT * FROM Library WHERE user = :user ORDER BY position DESC", user=self)
- return q.get().position
+ q = db.GqlQuery("SELECT * FROM Library WHERE user = :user ORDER BY position DESC", user=self)
+ p = q.get()
+ if p:
+ return p.position
+ else:
+ return -1
def re_sort_playlists(self, library_item, new_position):
@@ -40,16 +46,17 @@ def re_sort_playlists(self, library_item, new_position):
library_item.put()
elif library_item.position > new_position: #Moved up
+ entities_to_update = []
for p in playlists:
if (p.position < library_item.position and (p.position > new_position or p.position == new_position)):
p.position += 1
- p.put()
+ entities_to_update.append(p)
library_item.position = new_position
- library_item.put()
-
+ entities_to_update.append(library_item)
+ db.put(entities_to_update)
class Playlist(db.Model):
- name = db.StringProperty(required=True, default='Playlist')
+ name = db.TextProperty(required=True, default='Playlist')
date_created = db.DateTimeProperty(auto_now_add=True)
collaborative = db.BooleanProperty(default=False)
tracks = db.TextProperty(default="0")
View
0  robots.txt
No changes.
View
2  scripts/playlist.js
@@ -433,7 +433,7 @@ SC.Playlist.prototype = {
},
addToPlaylistsList: function() { // add the tab for the playlist
var self = this;
- $("<li listId='" + this.id + "' class='" + (this.properties.is_owner ? "" : "shared") + " " + (this.properties.playlist.collaborative ? "collaborative" : "") + " " + (this.persisted ? "" : "dont-persist") + " " + (this.properties.playlist.smart ? "smart" : "") + " " + (this.properties.playlist.search ? "search" : "") + "'><span></span><a href='#'>" + this.name + (this.properties.is_owner ? "" : " <em>by " + this.properties.playlist.owner.nickname + "</em>") + "</a><a class='collaborative' title='Make Playlist Collaborative' href='/playlists/" + this.id + "'>&nbsp;</a><a class='share' title='Share Playlist' href='/share/" + this.properties.playlist.share_hash + "'>&nbsp;</a><a class='delete' title='Remove Playlist' href='/playlists/" + this.id + "'>&nbsp;</a></li>")
+ $("<li listId='" + this.id + "' class='" + (this.properties.is_owner ? "" : "shared") + " " + (this.properties.playlist.collaborative ? "collaborative" : "") + " " + (this.persisted ? "" : "dont-persist") + " " + (this.properties.playlist.smart ? "smart" : "") + " " + (this.properties.playlist.search ? "search" : "") + "'><span></span><a href='#'>" + this.name + (this.properties.is_owner ? "" : " <em>by " + this.properties.playlist.owner.nickname + "</em>") + "</a><a class='collaborative' title='Make Playlist Collaborative' href='/playlists/" + this.id + "'>&nbsp;</a><a class='share' title='Share Playlist' href='/share/playlist/" + this.properties.playlist.share_hash + "'>&nbsp;</a><a class='delete' title='Remove Playlist' href='/playlists/" + this.id + "'>&nbsp;</a></li>")
.find('a:first').click(function(ev) {
if($(this).parents("li").hasClass("active") && self.properties.is_owner && $("body").hasClass("logged-in")) {
var that = this; // very strange that i can't use self here
View
26 the-cloud-player.py
@@ -49,7 +49,7 @@ def get(self):
if users.get_current_user() and not app_user:
app_user = utils.init_new_user()
- share_hash = utils.url_to_entity_key(self.request.uri)
+ share_hash = utils.url_to_share_key(self.request.uri)
q = db.GqlQuery("SELECT * FROM Playlist WHERE share_hash = :share_hash", share_hash=share_hash)
playlist = q.get()
@@ -65,6 +65,24 @@ def get(self):
self.redirect("/?flash="+flash)
+class ShareTrack(webapp.RequestHandler):
+ def get(self):
+ if not users.get_current_user():
+ self.redirect(users.create_login_url(self.request.uri))
+ else:
+ app_user = utils.get_current_user()
+ if users.get_current_user() and not app_user:
+ app_user = utils.init_new_user()
+
+ track_id = utils.url_to_share_key(self.request.uri)
+
+ playlist = models.Playlist(name = "Untitled", owner=app_user, tracks=track_id + ", ", share_hash = utils.generate_share_hash())
+ playlist.put()
+
+ library_item = models.Library(user=app_user, playlist=playlist, is_owner=True, position = app_user.last_lib_position()+1)
+ library_item.put()
+ self.redirect("/")
+
class Playlist(webapp.RequestHandler):
def get(self):
key = utils.url_to_entity_key(self.request.uri)
@@ -84,7 +102,7 @@ def post(self):
if method == "PUT":
if library_item.is_owner: #A bit special, does not need version handling
- if(self.request.get('name') && len(self.request.get('name')) > 0 ):
+ if(self.request.get('name') and len(self.request.get('name')) > 0 ):
playlist.name = utils.strip_html(self.request.get('name'))
playlist.put()
@@ -143,6 +161,7 @@ def post(self): #Create new playlist
utils.parse_smart_filters(playlist, self.request)
playlist.put()
+
library_item = models.Library(user=current_user, playlist=playlist, is_owner=True, position = int(self.request.get("position")))
library_item.put()
@@ -154,7 +173,8 @@ def main():
('/playlists/', Playlists),
('/playlists/.*', Playlist),
('/user', User),
- ('/share/.*', SharePlaylist),
+ ('/share/playlist/.*', SharePlaylist),
+ ('/share/track/.*', ShareTrack),
('/', PlayerPage)
], debug=True)
run_wsgi_app(application)
View
10 utils.py
@@ -47,6 +47,14 @@ def url_to_entity_key(url):
else:
return ""
+def url_to_share_key(url):
+ url_array = url.split("/")
+ if len(url_array) > 5:
+ return url_array[5]
+ else:
+ return ""
+
+
def convert_javascript_bool_to_python(s):
if s.lower() == "true":
return True
@@ -111,4 +119,4 @@ def parse_smart_filters(playlist, request):
return playlist
def strip_html(s):
- return re.replace('<.*?>', '', s)
+ return re.sub('<.*?>', '', s)
Please sign in to comment.
Something went wrong with that request. Please try again.