Example #1
0
    def get(self, bandid):
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url(self.request.uri))

        logging.info('bandid: ' + bandid)
        try:
            namespace_manager.set_namespace(bandid)
        except:
            self.error(400);
            return
        
        conf = Configuration.get_by_id("singleton")

        if conf.admin == None:
            conf.admin = user
            conf.put()

        if conf.admin != user:
            self.error(401);
            return

        template_values = {
            'admin': conf.admin,
            'users': conf.users,
            'auth_users': conf.auth_users,
            'bandid': bandid,
        }

        template = JINJA_ENVIRONMENT.get_template('config.html')
        self.response.write(template.render(template_values))
Example #2
0
    def post(self):
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url(self.request.uri))

        bandid = self.request.get('bandid')
        logging.info('bandid: ' + bandid)
        try:
            namespace_manager.set_namespace(bandid)
        except:
            self.error(400);
            return

        conf = Configuration.get_by_id("singleton")
        if user not in conf.auth_users:
            logging.info("letting an unauthed users vote... for now")

        votes = self.request.get_all('votes')
        for songid in votes:
            logging.info('songid:' + songid + 'len: ' + str(len(songid)))
            song = SongNode.get_by_id(songid)
            song_url=urllib.quote('/' + bandid + '/song/' + song.name + '/' + song.interpreter)
            if user not in song.votes:
                send_notifications(song,'http://' + self.request.host + song_url, 'vote', user)
                song.votes.append(user)
                song.vote_cnt += 1
                song.graduated = song.vote_cnt >= VOTES_TO_GRADUATE
                song.put()

        self.redirect('/' + bandid + '/thanks')
Example #3
0
    def get(self, bandid):
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url(self.request.uri))

        logging.info('bandid: ' + bandid)
        try:
            namespace_manager.set_namespace(bandid)
        except:
            self.error(400);
            return

        conf = Configuration.get_by_id("singleton")
        if user not in conf.users:
            conf.users.append(user)
            # TODO: For now users are authenticated by default.  This should
            # probably be a configuration parameter.
            conf.auth_users.append(user)
            conf.put()
        ranking_query = SongNode.query().order(-SongNode.vote_cnt)
        ranking_query = ranking_query.filter(SongNode.vote_cnt < conf.votes_to_graduate)
        songs = ranking_query.fetch(50)

        template_values = {
            'is_admin': conf.admin == user,
            'songs': songs,
            'band_name': conf.name,
            'bandid': bandid,
            'logout_uri': users.create_login_url(self.request.uri),
            'votes_to_graduate': conf.votes_to_graduate
        }

        template = JINJA_ENVIRONMENT.get_template('ranking.html')
        self.response.write(template.render(template_values))
Example #4
0
    def post(self):
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url(self.request.uri))

        bandid = self.request.get('bandid')
        logging.info('bandid: ' + bandid)
        try:
            namespace_manager.set_namespace(bandid)
        except:
            self.error(400);
            return

        conf = Configuration.get_by_id("singleton")
        if user not in conf.auth_users:
            logging.info("letting an unauthed users vote... for now")

        name = self.request.get('name').strip()
        interpreter = self.request.get('interpreter').strip()
        songid = name + interpreter
        song = SongNode.get_by_id(songid)
        if not song:
            song = SongNode(id=name+interpreter)
            song.name = name
            song.interpreter = interpreter
            song.vote_cnt = 0
            song.comments = [] 
            song.links = [] 
            song.votes = []
            song.graduated = False

            
        song_url=urllib.quote('/' + bandid + '/song/' + name + '/' + interpreter)
        unvote = self.request.get('undo', default_value=False)
        if user not in song.votes and not unvote:
            logging.info(str(user) + ' voted for ' + song.name)
            song.votes.append(user)
            song.vote_cnt += 1
            send_notifications(song,'http://' + self.request.host + song_url, 'vote', user)
        elif user in song.votes and unvote == 'true':
            logging.info(str(user) + ' unvoted for ' + song.name)
            song.votes.remove(user)
            song.vote_cnt -= 1
            send_notifications(song,'http://' + self.request.host + song_url, 'unvote', user)
        else:
            logging.error(str(user) + ' failed to vote/unvote for ' + song.name)
            return

        song.graduated = song.vote_cnt >= VOTES_TO_GRADUATE
        song.put()
        self.redirect(song_url)