예제 #1
0
 def remove_from_whitelist(self):
     for id in request.params.iterkeys():
         entry = Session.query(Whitelist).get(id)
         if entry:
             Session.delete(entry)
         Session.commit()
         redirect_to(action='manage_whitelist')
예제 #2
0
    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"
예제 #3
0
    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)
예제 #4
0
    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"
예제 #5
0
 def delete(self, id):
     playlist = Session.query(Playlist).get(int(id))
     if playlist.ownerid != session["userid"]:
         abort(404, "Cannot delete another man's playlist!")
     Session.delete(playlist)
     Session.commit()
     return "1"
예제 #6
0
 def _rmentity(self, rmclass):
     for id in request.params.iterkeys():
         entity = Session.query(rmclass).get(id)
         if entity:
             Session.delete(entity)
     Session.commit()
     redirect_to(action='rmentities')
예제 #7
0
 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!'
예제 #8
0
    def delete(self,id):
        if not id:
            abort(400)
        user = Session.query(User).get(session['userid'])
        spot = Session.query(Spotlight).get(id)
        if not spot or not spot in user.spotlights:
            abort(404)

        Session.delete(spot)
        Session.commit()
        user.update_profile()
        return "1"
예제 #9
0
 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)
예제 #10
0
    def playlist(self, id):
        if not request.params.has_key('comment') or not id:
            abort(400)

        comment = request.params['comment']

        user = Session.query(User).get(session['userid'])
        playlist = Session.query(Playlist).get(id)
        if playlist:
            spotlight = Spotlight(user=user, playlist=playlist, comment=comment)
            Session.add(spotlight)
            Session.commit()
            return str(spotlight.id)
        else:
            abort(404)
예제 #11
0
    def album(self, id):
        if not request.params.has_key('comment') or not id:
            abort(400)

        comment = request.params['comment']

        user = Session.query(User).get(session['userid'])
        album = Session.query(Album).get(id)
        if album:
            spotlight = Spotlight(user=user, album = album, comment=comment)
            Session.add(spotlight)
            Session.commit()
            return str(spotlight.id)
        else:
            abort(404)
예제 #12
0
 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"
예제 #13
0
    def remove(self, user, **kwargs):
        type = kwargs['type']
        id = kwargs['id']
        if not type or not id:
            abort(400)
        songs = user.song_query.filter(self.id_map[type]==id)
        if not songs:
            abort(404)
        for song in songs:
            user.remove_song(song)

        try:
            Session.commit()
        except Exception, e:
            Session.rollback()
            raise
예제 #14
0
    def edit(self, id):
        if not request.params.has_key('comment') or not id:
            abort(400)

        #id = request.params.get('spot_id')
        comment = request.params.get('comment')
        spotlight = Session.query(Spotlight).filter(Spotlight.id == id)[0]
        user = Session.query(User).get(session['userid'])
        if not spotlight or not spotlight in user.spotlights:
            abort(404)

        spotlight.comment = comment
        Session.add(spotlight)
        Session.commit()
        
        return "1"
예제 #15
0
    def feedback(self):
        if not request.params.has_key('email') or\
                not request.params.get('feedback'):
            return '0';
        user_email = request.params['email']
        user_feedback = request.params['feedback']
        user_browser = request.params.get('browser')

        browser = screen = user = ''
        user = Session.query(User).get(session['userid'])

        if user_browser:
            bdata = cjson.decode(urllib.unquote(user_browser))
            for key, value in bdata['browser'].items():
                browser = browser + "%s = %s\n" % (key, value)

            for key, value in bdata['screen'].items():
                screen = screen + "%s = %s\n" % (key, value)
        message = feedback_template % \
                (user_feedback, browser, screen)

        if (self.email_regex.match(user_email) != None):
            if user.email != user_email:
                user.email = user_email
                Session.add(user)
                Session.commit()
        else:
            user_email = None

        subject = 'harmonize.fm feedback from %s' % user.name
        
        def sendmail():
            cc = user_email
            if config['use_gmail'] == 'yes' or not user_email:
                frm = config['feedback_email']
                pword = config['feedback_password']
            else:
                frm = user_email
                pword = None
            mail(config['smtp_server'], config['smtp_port'],
                frm, pword,
                '*****@*****.**', subject, message, cc=cc)

        if not 'paste.testing_variables' in request.environ:
            thread.start_new_thread(sendmail, ())
        return '1'
예제 #16
0
 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')
예제 #17
0
        def set_now_playing():
            if not request.params.has_key('pid'):
                return 'false'

            song = Session.query(Song).get(request.params.get('pid'))
            user = Session.query(User).get(session['userid'])
            # we need to now add the database entries for this song being played.
            # this includes setting the now playing and updating the song statistic song and source
            if request.params.has_key('source'):
                src = int(request.params.get('source'))
                if src in SongStat.sources:
                    session['src'] = src

            user.nowplaying = song
            Session.add(user)
            Session.commit()
            user.update_profile()
            return 'true'
예제 #18
0
    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')
예제 #19
0
    def setup_user():
        session['fbsession']= facebook.session_key
        session['fbuid']= facebook.uid
        if request.params.get('present') == 'true':
            session['present'] = True

        if not qualified_for_login(facebook.uid, 1) and not \
                request.params.get('present') == 'true':
            return False

        user = Session.query(User).filter(
            User.fbid==facebook.uid).first()        
        if not user:
            user = create_user(facebook.uid)

        user.lastseen = datetime.now()
        user.fbsession = facebook.session_key

        Session.add(user)
        Session.commit()
        session['userid'] = user.id
        session.save()
        return True
예제 #20
0
    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"
예제 #21
0
 def set_volume(self, id):
     user = Session.query(User).get(session['userid'])
     user.lastvolume = id
     Session.add(user)
     Session.commit()
     return '1'
예제 #22
0
 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')