def add_spotcomment(self, id): comment = request.params.get('comment') if not comment or not id: abort(400) comment = h.util.html_escape(comment) spotcomment = SpotlightComment(session['userid'], id, comment) Session.save(spotcomment) Session.commit() # send facebook notification to the person who owns this spotlight # (unless its yours) spot = Session.query(Spotlight).get(spotcomment.spotlightid) if not spot.uid == session['userid']: owner = Session.query(User).get(spot.uid) fbml = " commented on <a href='http://harmonize.fm/player#/people/profile/" + str(owner.id) + "/spcomments/" + str(spot.id) + "' target='_blank'>" + spot.title + "</a>" response = facebook.notifications.send(owner.fbid, fbml) commenter = Session.query(User).get(session['userid']) subject = '%s has commented on your Spotlight' % commenter.name user_href = '<a href="http://harmonize.fm/player#people/profile/%s" target="_blank">%s</a>' % (commenter.id, commenter.name) body = '%s commented on <a href="http://harmonize.fm/player#people/profile/%s/spcomments/%s" target="_blank">%s.</a>' % \ (user_href, owner.id, spot.id, spot.title) facebook.notifications.sendEmail(owner.fbid, subject, text=body) return str(spotcomment.id)
def album(self, user, **kwargs): if not kwargs.get("entity") and kwargs.get("friend"): abort(400) album = Session.query(Album).get(kwargs["entity"]) if not album: abort(404) c.entity = album.title c.recommender = user c.recommendee = kwargs["friend"] c.href = "http://%s/player#/browse/friend=%s/album=%s/song" % ( request.host, session["userid"], kwargs["entity"], ) fbml = render("facebook/recommend.fbml.mako") facebook.notifications.send(c.recommendee, fbml) recommendee_obj = Session.query(User).filter(User.fbid == c.recommendee).first() if recommendee_obj: href = self._get_profile_href(recommendee_obj) subject = "%s has recommended you an album" % user.name body = '%s recommended you <a href="%s" target="_blank">%s</a> by %s.' % ( user.firstname, href, album.title, album.artist, ) facebook.notifications.sendEmail(c.recommendee, subject, text=body) rec = Recommendation(c.recommender.id, int(c.recommendee), albumid=album.id) Session.save(rec) Session.commit() self.whitelist_user(c.recommendee) return "1"
def playlist(self, user, **kwargs): if not kwargs.get("entity") and kwargs.get("friend"): abort(400) playlist = Session.query(Playlist).get(kwargs["entity"]) if not playlist: abort(404) c.entity = playlist.name c.recommender = user c.recommendee = kwargs["friend"] c.href = "http://%s/player#/browse/friend=%s/playlist=%s/playlistsong" % ( request.host, session["userid"], kwargs["entity"], ) fbml = render("facebook/recommend.fbml.mako") facebook.notifications.send(c.recommendee, fbml) recommendee_obj = Session.query(User).filter(User.fbid == c.recommendee).first() if recommendee_obj: href = self._get_profile_href(recommendee_obj) subject = "%s has recommended you a playlist" % user.name body = '%s recommended you a playlist <a href="%s">"%s"</a>.' % (user.name, href, playlist.name) facebook.notifications.sendEmail(c.recommendee, subject, text=body) rec = Recommendation(c.recommender.id, int(c.recommendee), playlistid=playlist.id) Session.save(rec) Session.commit() self.whitelist_user(c.recommendee) return "1"
def postblog(self): title = request.params.get('title') author = request.params.get('author') entry = request.params.get('entry') b = BlogEntry(title=title, author=author, entry=entry) Session.save(b) Session.commit() return 'Success!'
def create(self): name = request.params.get("name") uid = session.get("userid") if name and uid: playlist = Playlist(name[:255], uid) Session.save(playlist) Session.commit() qry = Session.query(*dbfields["playlist"]).filter(Playlist.id == playlist.id) json = build_json([qry.one()]) json["data"][0]["type"] = "playlist" return json else: abort(400)
def whitelist_user(self, user): # first check to see if the user is already in our database: qry = Session.query(User).filter(User.fbid == user) if qry.count() != 0: # user is already a member return "1" # now we check to see if they're already on the whitelist qry = Session.query(Whitelist).filter(Whitelist.fbid == user) if qry.count() != 0: # the user is already on the whitelist return "1" w = Whitelist(fbid=user, registered=False) Session.save(w) Session.commit() return "1"
def support(self): if request.params.has_key('email'): # we've submitted the form email = request.params.get('email') if (self.email_regex.match(email) == None): return render('/pages/support.mako.html') data = cjson.decode(urllib.unquote(request.params.get('browser'))) qry = Session.query(Notification).\ filter(Notification.email == email).\ filter(Notification.type == 'harmonizer') if qry.count() == 0: # this user hasn't already asked to be notified n = Notification(email, 'harmonizer', data = data) Session.save(n) Session.commit() return render('/pages/thankyou.mako.html') else: # we haven't submitted yet return render('/pages/support.mako.html')
def invitation(self): if request.params.has_key('email'): # we've submitted the form email = request.params.get('email') if (self.email_regex.match(email) == None): return render('/pages/sign-up.mako.html') qry = Session.query(Notification).\ filter(Notification.email == email).\ filter(Notification.type == 'release') if qry.count() == 0: # this user hasn't already asked to be notified n = Notification(email, 'release') Session.save(n) Session.commit() return render('/pages/thankyou.mako.html') else: # we haven't submitted yet return render('/pages/sign-up.mako.html')
def save(self): if not (request.params.has_key("playlist") or request.params.has_key("songs")): abort(400, "playlist or songs parameter not provided") user = Session.query(User).get(session["userid"]) playlist = int(request.params["playlist"]) playlistobj = ( Session.query(Playlist).filter(and_(Playlist.id == playlist, Playlist.ownerid == session["userid"])).first() ) if not playlistobj: abort(400) songs = request.params["songs"] old_pl_songs = playlistobj.songs for old_pl_song in old_pl_songs: Session.delete(old_pl_song) Session.commit() if songs != "": i = 0 for song in songs.split(","): try: songid = int(song) if not user.get_song_by_id(songid): raise ValueError except ValueError: abort(404) pl_song = PlaylistSong(playlist, i, songid) pl_song.playlist = playlistobj Session.save(pl_song) i += 1 Session.commit() return "1"
def add_to_whitelist(self): fbid = request.params.get('fbid') w = Whitelist(fbid=fbid, registered=False) Session.save(w) Session.commit() redirect_to(action='manage_whitelist')