예제 #1
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')
예제 #2
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"
예제 #3
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')
예제 #4
0
def create_user(fbid):
    user = User(fbid)
    if request.params.get('present' == 'true'):
        w = Whitelist(fbid=fbid, registered = False)
        Session.add(w)
    Session.add(user)
    user.add_me_to_friends()
    return user
예제 #5
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!'
예제 #6
0
def get_user():
    friendid = request.params.get('friend')
    if not friendid:
        user = Session.query(User).get(session['userid'])
    else:
        # TODO: Make sure they're friends
        user = Session.query(User).get(friendid)
        if not user:
            abort(400)
    return user
예제 #7
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)
예제 #8
0
 def find_by_playlist(self,user, **kwargs):
     id = kwargs['id']
     if not id:
         abort(400)
     
     playlist = Session.query(Playlist).filter(Playlist.id == id)
     if playlist.first():
         qry = Session.query(Spotlight).filter(and_(
                 Spotlight.playlistid == playlist[0].id,
                 Spotlight.uid == user.id,
                 Spotlight.active == 1))
         if qry.first():
             return "1"
     return "0"
예제 #9
0
    def songurl(self, friend, **kwargs):

        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'
 
        song = Session.query(Song).\
            join(Song.owners).filter(Song.id==int(kwargs['id']))
        song = song.first()
        if not song:
            abort(404)

        qsgen = S3.QueryStringAuthGenerator(
        config['S3.accesskey'], config['S3.secret'],
            is_secure = False
        )
        qsgen.set_expires_in(DEFAULT_EXPIRATION*60)
        if request.params.has_key('pid'):
            worked = set_now_playing();
        return qsgen.get(config['S3.music_bucket'], song.sha)
예제 #10
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
예제 #11
0
 def next_radio_song(self,user, **kwargs):
     #TODO: replace this with recommendations
     
     #songlist is a list where each element is a song id.
     #this will be used to generate a random number between 0 and the number
     #of songs (the length of the list)        
     songlist = []
     data = Session.query(*dbfields['song']).\
         join(Song.album).reset_joinpoint().\
         join(Song.artist).reset_joinpoint().\
         join(SongOwner)
     for friend in user.friends:
         # grab each users songs and append their song_ids to songlist
         temp = data.filter(SongOwner.uid == friend.id)
         for record in temp:
             songlist.append(record.Song_id)
     
     num_songs = len(songlist)
     if num_songs == 0:
         abort(404)
     song_index = random.randint(0,num_songs-1)
     song_id = songlist[song_index]
     
     #now grab the actual song data based on the song_id
     song = data.filter(Song.id == song_id)
     return song
예제 #12
0
 def find_by_album(self, user, **kwargs):
     id = kwargs['id']
     if not id:
         abort(400)
     album = Session.query(Album).filter(Album.id == id)
     if album.first():
         qry = Session.query(Spotlight).filter(and_(
                 Spotlight.albumid == album[0].id,
                 Spotlight.uid == user.id,
                 Spotlight.active == 1))
         if qry.first():
             return "1"
         else:
             return "0"
     else:
         return "0"
예제 #13
0
    def __before__(self):
        if not ensure_fb_session():
                redirect_to("/")

        user = Session.query(User).get(session['userid'])
        if not user.fbid in self.admin:
            redirect_to('/')
예제 #14
0
 def find_album(self, user, **kwargs):
     id = kwargs['id']
     if not id:
         abort(400)
     qry = Session.query(*dbfields['spotlight']).join(Spotlight.album).\
         join(Album.artist).filter(Spotlight.id == id).\
         filter(User.id == user.id)
     return qry.all()
예제 #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 find_playlist(self, user, **kwargs):
     id = kwargs['id']
     if not id:
         abort(400)
     qry = Session.query(*dbfields['spotlight']).\
     join(Spotlight.playlist).filter(Spotlight.id == id).\
     filter(User.id == user.id).limit(1)
     return qry.all()
예제 #17
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)
예제 #18
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')
예제 #19
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')
예제 #20
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"
예제 #21
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"
예제 #22
0
def get_asin(id,type):
    album = None

    if type == 'album':
        album = Session.query(Album).get(id)
    else:
        qry = Session.query(SongOwner).filter(SongOwner.uid == session['userid']).filter(SongOwner.songid == id)
        if qry.count() != 0:
            # user already has this song
            return "0"
        try:
            album = Session.query(Song).get(id).album
        except:
            return "0"
    if album:
        if album.mp3_asin:
            return album.mp3_asin
        elif album.asin:
            return album.asin
        else:
            return "0"
    else:
        return "0"
예제 #23
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
예제 #24
0
    def s3cleanup(self):
        a = S3.AWSAuthConnection(config['S3.accesskey'], config['S3.secret'])
        files = a.list_bucket(config['S3.music_bucket']).entries
        for file in files:
            db=Session.query(File).filter(File.sha==file.key).first()
            if db:
                files.remove(file)
        removed =[]
        for file in files:
            removed.append(file.key)
            if request.params.get('doit'):
                a.delete(config['S3.music_bucket'], file.key)

        return removed
예제 #25
0
    def home(self):
        user = Session.query(User).get(session['userid'])
        c.entries = user.feed_entries
        c.main = True
        c.user = user
        c.num_songs = c.user.song_count

        c.fbapp_href = "http://www.facebook.com/apps/application.php?id=%s" % \
            config['pyfacebook.appid']
        c.appid = config['pyfacebook.appid']
        if 'Windows' in request.headers['User-Agent']:
            c.platform = 'windows'
        elif 'Macintosh' in request.headers['User-Agent']:
            c.platform = 'mac'
        return render('/home.mako')
예제 #26
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"
예제 #27
0
def filter_friends(qry):
    """
    This function ensures that songs belong to you by default. If you are
    browsing a friend's music store, ensure that the songs belong to them.
    """
    friend = request.params.get('friend')
    friend_fbid = None
    if friend:
        friend_fbid = Session.query(User).get(friend).fbid
        friend = int(friend)

    if friend_fbid in session['fbfriends']:
        qry = qry.filter(User.id == friend)
    else:
        qry = qry.filter(User.id == session['userid'])
    return qry
예제 #28
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"
예제 #29
0
    def index(self):
        assert request.environ.get('HTTP_USER_AGENT'),\
            "Cannot serve to unidentified clients"

        c.profile = Profile()
        c.user = Session.query(User).get(session['userid'])
        c.fields = schema.fields
        c.fblogin_url = facebook.get_login_url(canvas=False)

        if snippets.is_ie6(request.environ['HTTP_USER_AGENT']):
            redirect_to('/ie6')

        if config.get('compressed') == 'true':
            c.include_files = compressed_player_files
        else:
            c.include_files = player_files

        return render('/player.mako')
예제 #30
0
    def artist(self, user, **kwargs):
        if not kwargs.get("entity") and kwargs.get("friend"):
            abort(400)
        artist = Session.query(Artist).get(kwargs["entity"])
        if not artist:
            abort(404)
        c.entity = artist.name
        c.recommender = user
        c.recommendee = kwargs["friend"]
        c.href = "http://%s/player#/browse/friend=%s/artist=%s/album" % (
            request.host,
            session["userid"],
            kwargs["entity"],
        )
        facebook.notifications.send(c.recommendee, render("facebook/recommend.fbml.mako"))

        self.whitelist_user(c.recommendee)
        return "1"