예제 #1
0
파일: main.py 프로젝트: dianafisher/yahtzee
    def get(self):
        """Send a reminder email to each User with an email who has
        games in progress. Email body includes a count of active games and their
        urlsafe keys
        Called every hour using a cron job"""
        app_id = app_identity.get_application_id()
        users = User.query(User.email != None)
        for user in users:
            # Query for Users which have games in progress.
            games = Game.query(Game.user == user.key).\
                filter(Game.game_over == False)
            if games.count() > 0:
                subject = 'This is a reminder!'
                body = 'Hello {}, you have {} games in progress. Their' \
                       ' keys are: {}'.\
                       format(user.name, games.count()
                        ,', '.join(game.key.urlsafe() for game in games))
                logging.debug(body)

            # This will send test emails, the arguments to send_mail are:
            # from, to, subject, body
            mail.send_mail('noreply@{}.appspotmail.com'.format(app_id),
                           user.email,
                           subject,
                           body)
예제 #2
0
파일: user.py 프로젝트: jlyden/straight-gin
 def all_games(self):
     """
     Return all user games - in progress and complete
     Reference: http://stackoverflow.com/questions/24392270/many-to-many-relationship-in-ndb
     """
     return Game.query(ndb.OR(Game.player_one == self.key,
                              Game.player_two == self.key))
예제 #3
0
파일: main.py 프로젝트: rootlis/blackjack
    def get(self):

        # Get a list of all games
        games = Game.query()
        games_out = [game.as_dict() for game in games]

        # Send the list to the user as JSON
        self.response.headers['Content/Type'] = 'application/json'
        self.response.out.write(json.dumps(games_out))
예제 #4
0
    def get_user_games(self, request):
        """Returns the user's active games."""

        # Query for a user with this user name.
        user = User.query(User.name == request.user_name).get()
        if not user:
            message = ('User {} not found!').format(request.user_name)
            raise endpoints.NotFoundException(message)
        # Query for all active games for this user.
        games = Game.query(Game.user == user.key).filter(
            Game.game_over == False)
        return GameForms(games=[game.to_form() for game in games])
예제 #5
0
파일: main.py 프로젝트: rootlis/blackjack
    def get(self):

        players = Player.query()
        games = Game.query()
        cards = Card.query()
        decks = Deck.query()

        ndb.delete_multi([p for p in players.iter(keys_only=True)])
        ndb.delete_multi([g for g in games.iter(keys_only=True)])
        ndb.delete_multi([c for c in cards.iter(keys_only=True)])
        ndb.delete_multi([d for d in decks.iter(keys_only=True)])

        self.response.headers['Content/Type'] = 'text/html'
        self.response.out.write('Deleted everything. Smooth move.')
예제 #6
0
 def get_games(self, request):
     """Returns all Games in the database."""
     return GameForms(games=[game.to_form() for game in Game.query()])