20090222 gae demo

31
The GAE The Demo The …… An Demo of GAE Hu Zi Ming [email protected] Feb 22, 2009 1 / 21 An Demo of GAE

Upload: linuxfb

Post on 12-May-2015

335 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

An Demo of GAE

Hu Zi [email protected]

Feb 22, 2009

.

.

.

.

1 / 21

.

An Demo of GAE

Page 2: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Outline

.

. .1 The GAE

The GAE

.

. .

2 The Demo

.

. .

3 The ……

.

.

.

.

2 / 21

.

An Demo of GAE

.

Page 3: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

The GAE

GAE means Google App Engine

Support Python only now

500MB storage space

Limited Python runtime

No file access

.

.

.

.

3 / 21

.

An Demo of GAE

.

Page 4: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Outline

.

. . 1 The GAE

.

. .

2 The DemoIntro of DemoConfigure this AppMapping the URLDatabase StructureDisplay the ContentsAdd RecordUser AuthenticationStatic Files

.

. .

3 The ……

.

.

.

.

4 / 21

.

An Demo of GAE

.

Page 5: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Intro of Demo

The idea is contributed by cooler

Maintain a list of cheaters

Using the cellphone number to identify the record

Records are classified by tags

.

.

.

.

5 / 21

.

An Demo of GAE

.

Page 6: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Intro of Demo

The idea is contributed by cooler

Maintain a list of cheaters

Using the cellphone number to identify the record

Records are classified by tags

.

.

.

.

5 / 21

.

An Demo of GAE

.

Page 7: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Configure this App

Set App id

Set URL mapping

Set handles for requests

Configure static resources

.

.

.

.

6 / 21

.

An Demo of GAE

.

Page 8: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Configure this App Cont.

.

YAML file for this App

.

.

.

. ..

.

.

application: mmcversion: 1runtime: pythonapi_version: 1

handlers:- url: /smedia

static_dir: smedia

- url: .*script: cheater.py

.

.

.

.

7 / 21

.

An Demo of GAE

.

Page 9: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Mapping the URL

Used for mapping different URL to its own handler

Regular expression can be used in this component

The mapping can be done in YAML file or handler

Pay a ention to the order of pa erns

.

.

.

.

8 / 21

.

An Demo of GAE

.

Page 10: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Mapping the URL

Used for mapping different URL to its own handler

Regular expression can be used in this component

The mapping can be done in YAML file or handler

Pay a ention to the order of pa erns

.

.

.

.

8 / 21

.

An Demo of GAE

.

Page 11: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Mapping the URL

Used for mapping different URL to its own handler

Regular expression can be used in this component

The mapping can be done in YAML file or handler

Pay a ention to the order of pa erns

.

.

.

.

8 / 21

.

An Demo of GAE

.

Page 12: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Mapping the URL Cont.

.

URL mapping in main handler

.

.

.

. ..

.

.

application = webapp.WSGIApplication([

('/', MainPage),('/add', AddRecord),(r'/tag/(.*)', ListTag),

],debug=True)

.

.

.

.

9 / 21

.

An Demo of GAE

.

Page 13: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Database Structure

The database contains those fields:Mobile phone numberBrief description (opt)Tags (opt)Who add this recordThe birthday of this record

The last two fields are updated by system instead of users’ input

.

.

.

.

10 / 21

.

An Demo of GAE

.

Page 14: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Database Structure

The database contains those fields:Mobile phone numberBrief description (opt)Tags (opt)Who add this recordThe birthday of this record

The last two fields are updated by system instead of users’ input

.

.

.

.

10 / 21

.

An Demo of GAE

.

Page 15: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Database Structure Cont.

.

Database scheme

.

.

.

. ..

.

.

class Cheater(db.Model):#mobile = db.PhoneNumberProperty()mobile = db.StringProperty()adder = db.UserProperty()add_date = db.DateTimeProperty(auto_now = True)desc = db.TextProperty()tags = db.StringListProperty()

.

.

.

.

11 / 21

.

An Demo of GAE

.

Page 16: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Display the Contents

Template system is used in GAE

Just has some minor differences between Django 0.96

The template can receive dict as “arguments”

And display it in specified place and style

The template is wri en in HTML

Some tags are used for data presentation

.

.

.

.

12 / 21

.

An Demo of GAE .

Page 17: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Display the Contents

Template system is used in GAE

Just has some minor differences between Django 0.96

The template can receive dict as “arguments”

And display it in specified place and style

The template is wri en in HTML

Some tags are used for data presentation

.

.

.

.

12 / 21

.

An Demo of GAE .

Page 18: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Display the Contents

Template system is used in GAE

Just has some minor differences between Django 0.96

The template can receive dict as “arguments”

And display it in specified place and style

The template is wri en in HTML

Some tags are used for data presentation

.

.

.

.

12 / 21

.

An Demo of GAE .

Page 19: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Display the Contents Cont.

.

Part of index page’s template

.

.

.

. ..

.

.

{% for rcd in rcds %}<tr class="{% cycle row1,row2 %}">

<td>{{ rcd.mobile }}</td><td>{{ rcd.desc }}</td><td>

{% for tag in rcd.tags %}<a href="/tag/{{ tag }}">{{ tag }}</a>,{% endfor %}

</td><td>{{ rcd.add_date|date:"Y-m-d H:i:s" }}</td>

</tr>{% endfor %}

.

.

.

.

13 / 21

.

An Demo of GAE .

Page 20: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Display the Contents Cont.

.

Handler for display contents

.

.

.

. ..

.

.

class MainPage(webapp.RequestHandler):def get(self):

cheaters = Cheater.all().order('-add_date')data_to_send = {'rcds' : cheaters,}

path = os.path.join(os.path.dirname(__file__), 'list.html')self.response.out.write(template.render(path, data_to_send))

.

.

.

.

14 / 21

.

An Demo of GAE .

Page 21: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Add Record

The post()method can be overloaded to deal with post data

The data can be fetched by self.request.get(<field name>)

The data will be saved to database a er verified

Then the system will redirect to the index page

.

.

.

.

15 / 21

.

An Demo of GAE .

Page 22: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Add Record

The post()method can be overloaded to deal with post data

The data can be fetched by self.request.get(<field name>)

The data will be saved to database a er verified

Then the system will redirect to the index page

.

.

.

.

15 / 21

.

An Demo of GAE .

Page 23: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Add Record

The post()method can be overloaded to deal with post data

The data can be fetched by self.request.get(<field name>)

The data will be saved to database a er verified

Then the system will redirect to the index page

.

.

.

.

15 / 21

.

An Demo of GAE .

Page 24: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Add Record Cont.

.

Part of AddRecord handler

.

.

.

. ..

.

.

def post(self):user = users.get_current_user()

if not user:self.display_page()

if len(self.request.get('mobile')) == 0:self.display_page('mobile is needed')

else:logging.info("rcds: mobile: %s" % self.request.get('mobile'))rcd = Cheater(mobile = self.request.get('mobile'),

adder = user,desc = self.request.get('desc'),tags = self.request.get('tags').split(','))

rcd.put()

self.redirect('/')

.

.

.

.

16 / 21

.

An Demo of GAE .

Page 25: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

User Authentication

User authentication has been shown in the previous code

user = users.get_current_user()

This interface is bound to the Google account

But have no effect during local developing phase

.

.

.

.

17 / 21

.

An Demo of GAE .

Page 26: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

User Authentication

User authentication has been shown in the previous code

user = users.get_current_user()

This interface is bound to the Google account

But have no effect during local developing phase

.

.

.

.

17 / 21

.

An Demo of GAE .

Page 27: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Static Files

Static files will be hidden in the cloud

Which can only be accessed by url mapping

It is forbidden to write the file in the GAE

Saving it in the database is a usable solution

.

.

.

.

18 / 21

.

An Demo of GAE .

Page 28: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Static Files

Static files will be hidden in the cloud

Which can only be accessed by url mapping

It is forbidden to write the file in the GAE

Saving it in the database is a usable solution

.

.

.

.

18 / 21

.

An Demo of GAE .

Page 29: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Outline

.

. .1 The GAE

.

. .

2 The Demo

.

. .

3 The ……Some Other APIQ and A

.

.

.

.

19 / 21

.

An Demo of GAE .

Page 30: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Some Other API

Memcache

URL fetch

Mail

Image

GData services

.

.

.

.

20 / 21

.

An Demo of GAE .

Page 31: 20090222 gae demo

.

.

The GAE

.

.

The Demo

.

.

The ……

Q AND A

.

.

.

.

21 / 21

.

An Demo of GAE .