• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
20090222 gae demo
 

20090222 gae demo

on

  • 417 views

 

Statistics

Views

Total Views
417
Views on SlideShare
417
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    20090222 gae demo 20090222 gae demo Presentation Transcript

    • The GAE The Demo The …… An Demo of GAE Hu Zi Ming hzmangel@gmail.com Feb 22, 2009 An Demo of GAE 1 / 21
    • The GAE The Demo The …… Outline 1 The GAE The GAE 2 The Demo 3 The …… An Demo of GAE 2 / 21
    • 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 An Demo of GAE 3 / 21
    • The GAE The Demo The …… Outline 1 The GAE 2 The Demo Intro of Demo Configure this App Mapping the URL Database Structure Display the Contents Add Record User Authentication Static Files 3 The …… An Demo of GAE 4 / 21
    • The GAE The Demo The …… Intro of Demo The idea is contributed by cooler An Demo of GAE 5 / 21
    • 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 An Demo of GAE 5 / 21
    • The GAE The Demo The …… Configure this App Set App id Set URL mapping Set handles for requests Configure static resources An Demo of GAE 6 / 21
    • The GAE The Demo The …… Configure this App Cont. YAML file for this App application: mmc version: 1 runtime: python api_version: 1 handlers: - url: /smedia static_dir: smedia - url: .* script: cheater.py . An Demo of GAE 7 / 21
    • 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 An Demo of GAE 8 / 21
    • 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 An Demo of GAE 8 / 21
    • 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 An Demo of GAE 8 / 21
    • 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) . An Demo of GAE 9 / 21
    • The GAE The Demo The …… Database Structure The database contains those fields: Mobile phone number Brief description (opt) Tags (opt) Who add this record The birthday of this record An Demo of GAE 10 / 21
    • The GAE The Demo The …… Database Structure The database contains those fields: Mobile phone number Brief description (opt) Tags (opt) Who add this record The birthday of this record The last two fields are updated by system instead of users’ input An Demo of GAE 10 / 21
    • 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() . An Demo of GAE 11 / 21
    • The GAE The Demo The …… Display the Contents Template system is used in GAE Just has some minor differences between Django 0.96 An Demo of GAE 12 / 21
    • 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 An Demo of GAE 12 / 21
    • 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 An Demo of GAE 12 / 21
    • 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 %} . An Demo of GAE 13 / 21
    • 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)) . An Demo of GAE 14 / 21
    • The GAE The Demo The …… Add Record The post() method can be overloaded to deal with post data An Demo of GAE 15 / 21
    • 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>) An Demo of GAE 15 / 21
    • 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 An Demo of GAE 15 / 21
    • 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(/) . An Demo of GAE 16 / 21
    • The GAE The Demo The …… User Authentication User authentication has been shown in the previous code user = users.get_current_user() An Demo of GAE 17 / 21
    • 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 An Demo of GAE 17 / 21
    • The GAE The Demo The …… Static Files Static files will be hidden in the cloud Which can only be accessed by url mapping An Demo of GAE 18 / 21
    • 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 An Demo of GAE 18 / 21
    • The GAE The Demo The …… Outline 1 The GAE 2 The Demo 3 The …… Some Other API Q and A An Demo of GAE 19 / 21
    • The GAE The Demo The …… Some Other API Memcache URL fetch Mail Image GData services An Demo of GAE 20 / 21
    • The GAE The Demo The …… Q AND A An Demo of GAE 21 / 21