def get(self, contest_id): categories = CATEGORIES.contest(contest_id) winners = self.store.fetch(Winner, contest_id) if not winners: winners = self.store.create(Winner, contest=contest_id) for category in categories: winner = self.store.fetch(Winner, category.key) if not winner: category.winner = None else: category.winner = winner.nominee vote_id = "{0}:{1}".format(contest_id, self.current_user.email) votes = self.store.fetch(Votes, vote_id) if not votes: votes = self.store.create( Votes, email=self.current_user.email, contest=contest_id) self.render( "contest.htm", categories=categories, votes=votes, winners=winners, contest_id=contest_id)
def get(self, contest_id, vote_id): categories = CATEGORIES.contest(contest_id) category = categories.get(vote_id) votes = self._get_votes(contest_id) return self.render( "vote.htm", category=category, votes=votes, vote_id=vote_id, categories=categories, contest_id=contest_id)
def progress(self): category_count = 0 categories = CATEGORIES.contest(self.contest) for category in categories: if category.key in self.winners: category_count += 1 return float(category_count) / len(categories)
def get(self, contest_id): categories = CATEGORIES.contest(contest_id) winners = self.store.fetch(Winner, contest_id) if not winners: winners = self.store.create(Winner, contest=contest_id) for category in categories: winner = self.store.fetch(Winner, category.key) if not winner: category.winner = None else: category.winner = winner.nominee vote_id = "{0}:{1}".format(contest_id, self.current_user.email) votes = self.store.fetch(Votes, vote_id) if not votes: votes = self.store.create(Votes, email=self.current_user.email, contest=contest_id) self.render("contest.htm", categories=categories, votes=votes, winners=winners, contest_id=contest_id)
def get_points(self, votes): points = 0 categories = CATEGORIES.contest(self.contest) for category, vote in votes.votes.items(): if vote == self.winners.get(category): points += categories.get(category).points return points
def remaining_points(self): points = 0 categories = CATEGORIES.contest(self.contest) for category in categories: if category.key not in self.winners: points += category.points return points
def post(self, contest_id, vote_id): winners = self.store.fetch(Winner, contest_id) if winners and winners.winners: return self.redirect( "/contests/{}?message=contest_started".format(contest_id)) categories = CATEGORIES.contest(contest_id) category = categories.get(vote_id) category_index = -1 for category in categories: category_index += 1 if category.key == vote_id: break nominee_id = self.get_argument("nominee") votes = self._get_votes(contest_id) votes.add_vote(vote_id, nominee_id) self.store.save(votes) next_category_key = None if len(categories) > category_index + 1: next_category_key = categories[category_index + 1].key return self.redirect("/contests/{}/votes/{}".format( contest_id, next_category_key)) return self.redirect("/")
def post(self, contest_id, vote_id): winners = self.store.fetch(Winner, contest_id) if winners and winners.winners: return self.redirect( "/contests/{}?message=contest_started".format(contest_id)) categories = CATEGORIES.contest(contest_id) category = categories.get(vote_id) category_index = -1 for category in categories: category_index += 1 if category.key == vote_id: break nominee_id = self.get_argument("nominee") votes = self._get_votes(contest_id) votes.add_vote(vote_id, nominee_id) self.store.save(votes) next_category_key = None if len(categories) > category_index + 1: next_category_key = categories[category_index + 1].key return self.redirect( "/contests/{}/votes/{}".format(contest_id, next_category_key)) return self.redirect("/")
def get(self, contest_id, vote_id): categories = CATEGORIES.contest(contest_id) category = categories.get(vote_id) votes = self._get_votes(contest_id) return self.render("vote.htm", category=category, votes=votes, vote_id=vote_id, categories=categories, contest_id=contest_id)
def setUp(self): super(TestWinner, self).setUp() self.store = FakeStore() self.user = self.store.create( User, name="Foo Bar", email="*****@*****.**", password="******") self.categories = CATEGORIES.contest(config.CONTEST_ID) self.winner = self.store.create(Winner, contest=config.CONTEST_ID) self.winner.add_winner( self.categories[0].key, self.categories[0].nominees[0].key) self.winner.add_winner( self.categories[1].key, self.categories[1].nominees[1].key)
def setUp(self): super(TestVotes, self).setUp() self.store = FakeStore() self.user = self.store.create( User, name="Foo Bar", email="*****@*****.**", password="******") self.votes = self.store.create( Votes, email=self.user.email, contest=config.CONTEST_ID) self.categories = CATEGORIES.contest(config.CONTEST_ID) category = self.categories[0] self.votes.add_vote(category.key, category.nominees[0].key) category = self.categories[1] self.votes.add_vote(category.key, category.nominees[1].key)
def setUp(self): super(TestWinner, self).setUp() self.store = FakeStore() self.user = self.store.create(User, name="Foo Bar", email="*****@*****.**", password="******") self.categories = CATEGORIES.contest(config.CONTEST_ID) self.winner = self.store.create(Winner, contest=config.CONTEST_ID) self.winner.add_winner(self.categories[0].key, self.categories[0].nominees[0].key) self.winner.add_winner(self.categories[1].key, self.categories[1].nominees[1].key)
def categories(self): return CATEGORIES.contest(config.CONTEST_ID)
def progress(self): categories = CATEGORIES.contest(self.contest) return float(len(self.votes)) / len(categories)
def get(self, contest_id): categories = CATEGORIES.contest(contest_id) self.redirect("/contests/{}/votes/{}".format(contest_id, categories[0].key))
def get(self, contest_id): categories = CATEGORIES.contest(contest_id) self.redirect("/contests/{}/votes/{}".format( contest_id, categories[0].key))