def get(self, bandid, name, interpreter): 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 song = SongNode.get_by_id(name+interpreter) if not song: logging.error("Cant find song id = " + name + interpreter) self.error(404); return template_values = { 'song': song, 'last_update': fuzzy_readable_time(datetime.datetime.now() - song.last_update), 'bandid': bandid, 'user_has_voted': user in song.votes } template = JINJA_ENVIRONMENT.get_template('song.html') self.response.write(template.render(template_values))
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 name = self.request.get('name') interpreter = self.request.get('interpreter') comment = self.request.get('comment') song = SongNode.get_by_id(name+interpreter) if not song: self.error(404) song.comments.append(comment + ' (' + user.nickname() + ')') song.put() song_url=urllib.quote('/' + bandid + '/song/' + song.name + '/' + song.interpreter) send_notifications(song,'http://' + self.request.host + song_url, 'comment', user) self.redirect(song_url)
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))
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')
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 ranking_query = SongNode.query() ranking_query = ranking_query.filter(SongNode.graduated == False) week_old = datetime.datetime.now() - datetime.timedelta(days=7) ranking_query = ranking_query.filter(SongNode.last_update < week_old) stale_songs = ranking_query.fetch(keys_only=True) ndb.delete_multi(stale_songs) ranking_query = SongNode.query() ranking_query = ranking_query.filter(SongNode.vote_cnt == 0) abandoned_songs = ranking_query.fetch(keys_only=True) ndb.delete_multi(abandoned_songs) self.response.write("Purge successful")
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 ranking_query = SongNode.query().order(-SongNode.vote_cnt) ranking_query = ranking_query.filter(SongNode.vote_cnt >= VOTES_TO_GRADUATE) songs = ranking_query.fetch() template_values = { 'songs': songs, 'bandid': bandid, 'logout_uri': users.create_login_url(self.request.uri) } template = JINJA_ENVIRONMENT.get_template('repertoire.html') self.response.write(template.render(template_values))
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)