def post(self): token_string = self.request.get("token") num_votes = self.request.get("votes") token = Token.query(Token.value == token_string).get() if not token: return game = token.game.get() voter = token.voter.get() num_votes = self.request.get("votes") if num_votes == "1": votes_text = "1 vote" else: votes_text = num_votes + " votes" template = jinja_environment.get_template("templates/self_vote_email.txt") if game.team == Team.WOMEN: pronoun = "herself" else: pronoun = "himself" subject = "OUARFC: " + voter.name + " tried to give " + pronoun + " " + votes_text message = mail.EmailMessage(sender="OUARFC <*****@*****.**>", subject=subject) message.to = "*****@*****.**" message.body = template.render( {"name": voter.name, "opponent": game.opponent, "date": game.date, "pronoun": pronoun, "votes": votes_text} ) message.send() logging.info(message.body) vote = SelfVote(game=game.key, voter=voter.key) vote.put()
def delete_game(self, game): tokens = Token.query(Token.game == game.key) keys = [token.key for token in tokens] votes = Vote.query(Vote.game == game.key) keys.extend([vote.key for vote in votes]) votes = SelfVote.query(SelfVote.game == game.key) keys.extend([vote.key for vote in votes]) ndb.delete_multi_async(keys) game.key.delete()