CS4HS Using Google App Engine. Michael Parker

Similar documents
web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment.

Chapter 19: Twitter in Twenty Minutes

Google App Engine Data Store. Google is BIG. Advanced Stuff.

Hons. B.Sc. Degree in Software Engineering/Development. Web and Cloud Development

CS2021- Week 10 Models and Views. Model, View, Controller. Web Development Model, Views, Controller Templates Databases

webapp2 Documentation

A Sample Approach to your Project

Google & the Cloud. GData, Mashup Editor, AppEngine. Gregor Hohpe Software Engineer Google, Inc. All rights reserved,

Building Python web app on GAE

Google App Engine Using Templates

LECTURE 14. Web Frameworks

APACHE SLING & FRIENDS TECH MEETUP BERLIN, SEPTEMBER Hypermedia API Tools for Sling (HApi) Andrei Dulvac, Adobe

App Engine Web App Framework

CS2021-Week 9 - Forms. HTML Forms. Python Web Development. h?ps:// cs253/unit-2html. Form for Submitting input:

App Engine Web App Framework

Developing with Google App Engine

Installing and Running the Google App Engine On a Macintosh System

A website is a way to present your content to the world, using HTML to present that content and make it look good

Lecture 10(-ish) Web [Application] Frameworks

Rapid Development with Django and App Engine. Guido van Rossum May 28, 2008

TailorDev Contact Documentation

LECTURE 14. Web Frameworks

Server-Side Web Programming: Python (Part 1) Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

Forms, CGI. Objectives

Building Scalable Web Apps with Python and Google Cloud Platform. Dan Sanderson, April 2015

Slide 1. Chapter 5. How to use the MVC pattern to organize your code. 2010, Mike Murach & Associates, Inc. Murach's PHP and MySQL, C5

Developing Solutions for Google Cloud Platform (CPD200) Course Agenda

CS 112 Introduction to Programming

Building Production Quality Apps on App Engine. Ken Ashcraft 5/29/2008

Chapter 11. How to create and use arrays. 2010, Mike Murach & Associates, Inc. Murach's PHP and MySQL, C11

1 Form Basics CSC309

Information Retrieval CS Lecture 13. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Scala for Sling. Building RESTful Web Applications with Scala for Sling. LOGO SPEAKER S COMPANY

django-xross Documentation

CS 350 COMPUTER/HUMAN INTERACTION. Lecture 6

CSC 405 Computer Security. Web Security

Produced by. Web Development. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology

Creating a Custom TinyWebDB service

How to use the MVC pattern to organize your code

Clojure Web Security. FrOSCon Joy Clark & Simon Kölsch

Manual Html A Href Onclick Submit Form

Flask Web Development Course Catalog

CCS Lab FAQ: Using Google App Engine to host websites

Flask Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : May, More documents are freely available at PythonDSP

Forms, CGI. Cristian Bogdan 2D2052 / 2D1335 F5 1

Homework #7 Google Cloud Platform

pyrauth Documentation

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

Scaling Rails on App Engine with JRuby and Duby

Web Architecture and Development

Jquery Ajax Json Php Mysql Data Entry Example

So we broke all CSPs. You won't guess what happened next!

Google Cloud Platform for Systems Operations Professionals (CPO200) Course Agenda

COMP 2406: Fundamentals of Web Applications. Fall 2013 Mid-Term Exam Solutions

Web Development and HTML. Shan-Hung Wu CS, NTHU

Chapter 4 Sending Data to Your Application

Form Overview. Form Processing. The Form Element. CMPT 165: Form Basics

Web Focused Programming With PHP

core programming HTML Forms Sending Data to Server-Side Programs Marty Hall, Larry Brown

How to create and use arrays

HOW TO FLASK. And a very short intro to web development and databases

Forms, CGI. HTML forms. Form example. Form example...

XAP: extensible Ajax Platform

Web Architecture and Development

20486: Developing ASP.NET MVC 4 Web Applications

Week - 01 Lecture - 04 Downloading and installing Python

Interactive Web Application

CIT 590 Homework 5 HTML Resumes

Full Stack Web Developer

Quick housekeeping Last Two Homeworks Extra Credit for demoing project prototypes Reminder about Project Deadlines/specifics Class on April 12th Resul

The Pyramid Web Application Development Framework

Secure Parameter Filter (SPF) (AKA Protecting Vulnerable Applications with IIS7) Justin Clarke, Andrew Carey Nairn

Creating Web Pages Using HTML

Storing Your Application s Data in the Google Cloud

HTML Forms. By Jaroslav Mohapl

How to use PHP with a MySQL database

Lecture 9. Forms & APIs 1 / 38

LICENSE4J AUTO LICENSE GENERATION AND ACTIVATION SERVER USER GUIDE

Building Web Applications. Fall Forecast 2009

HTML 5 Form Processing

Developing Ajax Applications using EWD and Python. Tutorial: Part 2

CIS192 Python Programming

CS193X: Web Programming Fundamentals

Webdev: Building Django Apps. Ryan Fox Andrew Glassman MKE Python

Developing ASP.NET MVC 4 Web Applications

How to structure a web application with the MVC pattern

Let's Play... Try to name the databases described on the following slides...

Oracle WebLogic Server 12c: Administration I

Django: Views, Templates, and Sessions

How to Make a Contact Us PAGE in Dreamweaver

CSE 154 LECTURE 8: FORMS

CSE 115. Introduction to Computer Science I

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Meteor

Django urls Django Girls Tutorial

Templates and Databinding. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Web Programming and Design. MPT Senior Cycle Tutor: Tamara Week 1

Understanding this structure is pretty straightforward, but nonetheless crucial to working with HTML, CSS, and JavaScript.

Connecting Angular and CFML

COURSE 20486B: DEVELOPING ASP.NET MVC 4 WEB APPLICATIONS

COURSE OUTLINE MOC 20488: DEVELOPING MICROSOFT SHAREPOINT SERVER 2013 CORE SOLUTIONS

Transcription:

CS4HS Using Google App Engine Michael Parker (michael.g.parker@gmail.com)

So what is it? What's it for? Building and running web applications Why use it? Handles serving web pages, efficiently storing and retrieving lots of data Allows authenticating users, sending email and IMs, downloading remote files Easy management; don't need to buy or administer servers Supports both Python and Java Get the SDK at https://developers.google. com/appengine

Outline Some background + DEMO! Building the app Defining the data Writing the server-side code Deployment + Conclusion

The Demo and Some Other Stuff Go to http://cs4hs-tasklist.appspot.com

Start with a mock-up

Identify your data (nouns)

Identify your actions (verbs)

The mock-up: creating a task <h3>add a new task:</h3> <form id="new_form" action="create" method="post"> Summary: <input type="text" name="summary" value="" /> Description: <textarea name="body" rows="5"></textarea> <input type="submit" value="add Task" /> </form>

The mock-up: showing/deleting tasks <h3>task list for mgp@google.com:</h3> <form id="delete_form" action="delete" method="post"> <ul> <li> <input type="checkbox" name="task_id" value="task_id_1" /> <h4>make cs4hs slides</h4> <div>those will be the slides i'm presenting</div> </li> <li> <input type="checkbox" name="task_id" value="task_id_2" /> <h4>give presentation</h4> <div>hopefully to a thunderous applause</div> </li> </ul> <input type="submit" value="delete Tasks" /> </form>

Anatomy of a web application Reading data: 1 HTTP GET /index.html username=user@domain.com 4 <html>... <li><h3>title1</h3>body1</li> <li><h3>title2</h3>body2</li>... </html> Web Server /index.html handler /create.html handler /delete.html handler 2 Get tasks for user@domain.com 3 task1: (title1, body1) task2: (title2, body2) Storage

Anatomy of a web application Modifying data (add, edit, delete): 1 HTTP POST /create.html username=user@domain.com title=title3, body=body3 5 <html>... <li><h3>title1</h3>body1</li> <li><h3>title2</h3>body2</li> <li><h3>title3</h3>body3</li>... </html> Web Server /index.html handler /create.html handler /delete.html handler Create task for user@domain.com: title=title3, body=body3 3 2 Get tasks for mgp@google.com 4 task1: (title1, body1) task2: (title2, body2) task3: (title3, body3) Storage

Defining and Manipulating Data

Defining your data Extend db.model and define properties: class Task(db.Model): """A saved task.""" creator = db.userproperty() summary = db.stringproperty() body = db.textproperty()

Inserting new data Class db.model provides a put method: def NewTask(user, summary, body): """Creates a new task. Arguments: user: The user who is creating the task. summary: A summary of the task. body: The full description of the task. """ task = Task() task.creator = user task.summary = summary task.body = body task.put()

Retrieving data Add identifiers so they can be deleted later: def GetTasks(user): """Returns all tasks created by the given user. Arguments: The user to return tasks for. Returns: A list of tasks created by the given user. """ query = db.query(task) query.filter('creator =', user) tasks = query.fetch(1000) for task in tasks: task.id = str(task.key()) return tasks

Writing the /index.html Handler

Retrieving tasks class GetTasksHandler(webapp.RequestHandler): """Displays all tasks for the user, and a form to enter a new task. """ def get(self): if users.getcurrentuser() is None: login_url = users.createloginurl(self.request.uri) self.redirect(login_url) else: write_html(self.response)

Retrieving tasks def write_html(response, template_values={}): """Writes the tasks for the user in HTML. Arguments: response: The connection to the user template_values: Any additional template values to render """ user = users.getcurrentuser() user_tasks = tasks.gettasks(user) template_values['user'] = user template_values['tasks'] = user_tasks rendered_page = template.render( _TEMPLATE_PATH, template_values) response.out.write(rendered_page)

A look at template_values { "user": "mgp@google.com", "tasks": [ { "id": "task_id_1", "summary": "make cs4hs slides", "body": "those will be the slides i'm presenting", }, { "id": "task_id_2", "summary": "give presentation", "body": "hopefully to a thunderous applause", } ] }

A look at the template <h3>task list for {{ user }}:</h3> <form id="delete_form" action="delete" method="post"> <ul> {% for task in tasks %} <li> <input type="checkbox" name="task_id" value="{{ task.id }}" /> <h4>{{ task.summary }}</h4> <div>{{ task.body }}</div> </li> {% endfor %} </ul>...

The rendered output <h3>task list for mgp@google.com:</h3> <form id="delete_form" action="delete" method="post"> <ul> <li> <input type="checkbox" name="task_id" value="task_id_1" /> <h4>make cs4hs slides</h4> <div>those will be the slides i'm presenting</div> </li> <li> <input type="checkbox" name="task_id" value="task_id_2" /> <h4>give presentation</h4> <div>hopefully to a thunderous applause</div> </li> </ul>...

Writing the /create.html Handler

Creating tasks class NewTaskHandler(webapp.RequestHandler): """Handler that creates a new task.""" def post(self): user = users.getcurrentuser() summary = self.request.get('summary') body = self.request.get('body') tasks.newtask(user, summary, body) self.redirect('/index.html')

Creating tasks with error handling class NewTaskHandler(webapp.RequestHandler): """Handler that creates a new task.""" def post(self): user = users.getcurrentuser() summary = self.request.get('summary', None) body = self.request.get('body', None) if not summary or not body: self.handle_error(summary, body) return tasks.newtask(user, summary, body) self.redirect('/')

Creating tasks... def handle_error(self, summary, body): new_task_template_values = {} new_task_template_values['has_error'] = True if summary: new_task_template_values['summary'] = summary if body: new_task_template_values['body'] = body template_values = {} template_values['new'] = new_task_template_values write_html(self.response, template_values)

A look at template_values { "user": "mgp@google.com", "tasks": [ { "id": "00001", "summary": "make cs4hs slides", "body": "those will be the slides i'm presenting", }, { "id": "00002", "summary": "give presentation", "body": "hopefully to a thunderous applause", } ], "new": { "has_error": True, "summary":..., "body":..., } }

A look at the template <h3>add a new task:</h3> <form id="new_form" action="new" method="post"> {% if new.has_error %} <div class="error">please enter both a summary and description below</div> {% endif %} Summary: <input type="text" name="summary" value="{{ new.summary }}" /> Description: <textarea name="body" rows="5">{{ new.body }}</textarea> <input type="submit" value="add Task" /> </form>

Deployment and Wrapping Up

Deployment Prerequisites: Download the SDK Get the code from https://github.com/mgp/cs4hs-tasklist Import project into GoogleAppEngineLauncher Running it locally: In GAELauncher, click Run, then Browse Data is stored on your hard drive Can edit the code without restarting the web server Deploying it to the web: Register the application name at http://appengine.google. com Change application value in app.yaml to app name In GAELauncher, click Deploy See it at http://app-name.appspot.com

Questions?