def get(self, track_id) : track = Track.get_by_id(int(track_id)) if(track): logging.info("Track found on Phonoblaster") shortname = track.station.shortname user_agent = self.request.headers["User-Agent"] facebook_agent = "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)" if(user_agent != facebook_agent): # Redirect to live station self.redirect("/" + shortname) else: # Facebook linter self.station_proxy = StationApi(shortname) template_values = { "track": track, } self.render("station/facebook/track.html", template_values) else: # 404 error self.render("station/404.html", None)
def post(self): content = json.loads(self.request.get("content")) response = False; if(content["track_id"]): track = Track.get_by_id(int(content["track_id"])) # Check if the track exists on Phonoblaster if(track): profile = self.user_proxy.profile profile_proxy = StationApi(profile["shortname"]) profile_proxy.add_to_likes(track) response = True self.response.out.write(json.dumps({ "response": response }))
def delete(self, id): track = Track.get_by_id(int(id)) response = False if(track): # Queriying datastore for associated Like query = Like.all() query.filter("track", track) query.filter("listener", self.user_proxy.user.profile) like = query.get() if like: logging.info("Like associated to track_id %s and listener %s retrieved from datastore."%(id, self.user_proxy.profile["name"])) like.delete() response = True logging.info("Like is now deleted from datstore") else: logging.info("Like associated to track_id %s and listener %s does not exist in datastore."%(id, self.user_proxy.profile["name"])) self.response.out.write(json.dumps({ "response": response }))
def delete(self, id): track = Track.get_by_id(int(id)) shortname = track.station.shortname logging.info("Getting from datastore track with track_id = "+id+" for station : @"+shortname) response = True if(track): # Station Proxy station_proxy = StationApi(shortname) # Deleting associated broadcasts and favorites broadcasts_in_buffer = db.get(station_proxy.station.broadcasts) # If track associated to broadcast in buffer, track will not be deleted. # If not, a task queue will start to delete broadcast, favorites and the actual track for b in broadcasts_in_buffer: if b.track.key().id() == int(id): logging.info("Track is being broadcast, will not proceed to deletion.") response = False break if response: logging.info("Starting taskqueue to delete broadcasts and likes associated to track.") task = Task( method = 'DELETE', url = "/taskqueue/deletetrack", params = { "track_id": id, "type": "broadcast", }, ) task.add(queue_name="worker-queue") else: response = False self.response.out.write(json.dumps({ "response": response }))
def delete(self): cursor = self.request.get("cursor") track_id = self.request.get("track_id") typeModel = self.request.get("type") if(track_id): track = Track.get_by_id(int(track_id)) logging.info("Getting from datastore track with track_id = " + track_id) if(track): logging.info("Track found") if(typeModel == "broadcast"): # Deleting broadcasts associated to track query = Broadcast.all() query.filter("track", track) if(cursor): logging.info("Cursor found") query.with_cursor(start_cursor = cursor) broadcasts = query.fetch(100) logging.info("Fetched : %d Broadcast(s) from datastore."%(len(broadcasts))) if(len(broadcasts)>0): db.delete(broadcasts) logging.info("Deleted : %d Broadcast(s) from datastore."%(len(broadcasts))) task = Task( method = 'DELETE', url = "/taskqueue/deletetrack", params = { "cursor": cursor, "track_id": track_id, "type": typeModel, } ) task.add(queue_name="worker-queue") else: task = Task( method = 'DELETE', url = "/taskqueue/deletetrack", params = { "track_id": track_id, "type": "like", } ) task.add(queue_name="worker-queue") elif (typeModel == "like"): # Deleting likes associated to track query = Like.all() query.filter("track", track) if(cursor): logging.info("Cursor found") query.with_cursor(start_cursor = cursor) like = query.get() if like is None: logging.info("No like for this track, deleting track.") track.delete() else: try: listener_proxy = StationApi(like.listener.shortname) listener_proxy.decrement_likes_counter() logging.info("Listener Like counter decremented") except: logging.info("User has not created a station (likes used to be linked to user to stations)") Track.decrement_likes_counter(track.key().id()) logging.info("Track likes counter decremented") like.delete() logging.info("Like deleted from datastore") cursor = query.cursor() task = Task( method = 'DELETE', url = "/taskqueue/deletetrack", params = { "cursor": cursor, "track_id": track_id, "type": typeModel, } ) task.add(queue_name="worker-queue") response = True else: response = False self.response.out.write(json.dumps({ "response": response }))