Home Page After the user logs in, the application displays the following three lists of information: • Invitations – This list shows up to the 10 most recent invitations from others that are pending acceptance by the user who is logged in. In the preceding screenshot, user1 has invitations from user5 and user2 pending. • Games In-Progress – This list shows up to the 10 most recent games that are in progress. These are games that the user is actively playing, which have the status IN_PROGRESS . In the screenshot, user1 is actively playing a tic-tac-toe game with user3 and user4. • Recent History – This list shows up to the 10 most recent games that the user finished, which have the status FINISHED . In game shown in the screenshot, user1 has previously played with user2. For each completed game, the list shows the game result. In the code, the index function (in application.py ) makes the following three calls to retrieve game status information: inviteGames = controller.getGameInvites(session["username"]) inProgressGames = controller.getGamesWithStatus(session["username"], "IN_PRO GRESS") finishedGames = controller.getGamesWithStatus(session["username"], "FINISHED") Each of these calls return a list of items from DynamoDB that are wrapped by the Game objects. It is easy to extract data from these objects in the view. The index function passes these object lists to the view to render the HTML. return render_template("index.html", user=session["username"], invites=inviteGames, inprogress=inProgressGames, finished=finishedGames) The Tic-Tac-Toe application defines the Game class primarily to store game data retrieved from DynamoDB. These functions return lists of Game objects that enable you to isolate the rest of the application from code related to Amazon DynamoDB items.Thus, these functions help you decouple your application code from the details of the data store layer. The architectural pattern described here is also referred as the model-view-controller (MVC) UI pattern. In this case, the Game object instances (representing data) are the model, and the HTML page is the view. The controller is divided into two files. The application.py file has the controller logic for the API Version 2012-08-10 524 Amazon DynamoDB Developer Guide 2.2: Application in Action (Code Walkthrough)
Flask framework, and the business logic is isolated in the gameController.py file.That is, the application stores everything that has to do with DynamoDB SDK in its own separate file in the dynamodb folder. Let us review the three functions and how they query the Games table using global secondary indexes to retrieve relevant data.
You've reached the end of your free preview.
Want to read all 796 pages?
- Fall '14
- Data Management, ........., Amazon Web Services, Amazon River, Amazon Elastic Compute Cloud