陳信屹  Hsin Yi, Chen Hychen  (usually use in internet) Let's Start GAEO 2008/12 /20 Kalug metting A web framwork. [email_address] [email_address] http://hychen.wuweig.org
有時, 我們需要寫個小網站…
但是有些事 我 們 不 想 處 理 Web server 哪個 好 ? Db 要 用哪 一種 ? 記憶 體又 爛 了 網路 又斷了, 該死 的 種花電信 這樣 我 投影片 怎麼作 ? email 又 寄不出去 又 被 XXX 當 廣告信 不 是 正妹 的 電腦 我 不想 修 理 很 我  懶 很   我  懶
Python  我們需要一個 solution Goggle App Engine  好像不錯 ? 免費 免費 免費
買空賣空掏空的好所在
但是有人覺得  Google  這台引擎 不太順 ....
Erisck 我是不是該弄個機油潤滑一下 ?
Google App Engine Oil Hi, I am Erisck GAEO( 尬意喔 ) Google App Engien Oil  作者 Erisck ver 0.2, since 2008 Web Framwork 台灣製造 這個油絕對不會 漲價 Erisck
Model Use Google App Engine Datastore API Model Relation Mapper Many To One: belonss_to() Many To Many: Not Implment yet (0.2 release) Has useful attributes updates method. model_obj.update_attributes(name='hi') model_obj.update_attributes({name:'hi'})
So, GAEO Is Also MVC Model / Controller / View
GAEO is a MVC Framwork Model GAE Datastore Model Controller POST/GET/PUT/DELETE View XML/HTML/JSON/TEXT/IMAGE HTML Template Engine Django Template
架構 架構
http://example.org/home   Which controller ? Which action ?
Original GAE URl Routing Django like app.yaml urls.py in django Regex supported Easy config? Easy understand? I don't know handlers: - url: /css static_dir: assets/css - url: /js  static_dir: assets/js
GAEO URL Routing Rails lik main.py Regex supported Easy understand Easy config It's more eazy than orginal configure to me r.connect('/about/', \ controller='welcome',  \ action="about") #  http://example.org/welcome/  \ about  r.connect('/:controller/:action/:id') # http//example.org/ctrl/act/1
架構 架構
Controller Do action to render View
How to get data from GET/POST PHP $_GET['缺']; $_POST[''錢”]; GAEO  GET/POST datas are all in self.params variable Class LifeController(BaseController): def need_money(self): print self.params['缺'] print self.params['錢']
Get params http://example.org/welcome/about/xFjddeY Class WelcomeController(BaseController): def aboutz(self): self.params = {'id':'xFjddeY'} http://example.org/welcome/about/?user=1&is_guest=y Class WelcomeController(BaseController): def aboutz(self): self.params = {'id':'':,'user':1,'is_guest':'y'}
How to storage data in session? Implement by GAE memcache. PHP  $_SESSION['正妹'] = "國字臉才叫正” GAEO Class GirlController(BaseController): def catch(self): self.session['正妹']  = ”國字臉才叫正” self.session['正妹'].put()
推 Remember  PUT 倒 self.session[' 正妹 '].put()
How to get data from session? PHP  echo $_SESSION['正妹們']  GAEO Class GirlController(BaseController): def catched_list(self): print self.session['正妹們']
How to storage data in cookie? PHP  $_COOKIE[' 阿宅說 '] = " 有 MSN 也沒用,我不敢跟女生說話” $_COOKIE[' 標準答案 '] = "MSN ID  都是中性的 , 在 XX 之前把他當人妖” set_cookie() GAEO Class AJaiController(BaseController): def show_anwser(self): self.cookie[' 阿宅說 '] = .... self.cookie[' 阿宅說 '] = ....
How to get datas from cookie? PHP  echo $_COOKIE['大宅門']  GAEO Class GirlController(BaseController): def be_master(self): print self.cookie['大宅門'] # !!! KeyError: '大宅門'
But How to Set Expier time?
404   Not Found
製作簡報時 網路大斷線 所以沒什麼機會查資料
簡報總是快來不及時做 但請儘量不要這樣,最起碼在還有網路時就做完… 歷來慣例,
How to get request Class Controller: def __demo__(self): self.request
View HTML / XML / JSON / More Wait! How to use template engine in GAEO?
Render HTML Django Template Markup Controller attribute be template variable automaticlly __dict__ Class  CatchController(...): def show(self): self.viewer = {'name':' 正妹 ',   ''age”:18} /project/applications/templates/catch/show .html <h1>{{viewer.name}}</h2> {{self.request}} {{self.params}}
Render Json Class Controller: def render_json(self): self.render(json=self.to_json({'1':'1'})
Render XML Google app engine model can convert to xml Class Controller: def render_xml(self): xml_content = model_obj.to_xml() self.render(xml=self.to_xml(xml_content)
Plugin Every application has its plugin architecture...
GAEO Plugin Save your time! You/Other people can write a plugin to Extends BaseController class Extends BaseModel class Extends GAEO more powerful! Help web app developement quickly and easir. Ok, It looks more like Rails.... Collection site: http://plugins.gaeo.org plugins are very few now... we need yours!
How does plugin work? All plugins are saved in $project/plugins Init function in main.py Load before the application started. All magic are in the file Project root ~/catchgirl/ Project Plugins Dir ~/catchgirl/plugins/ Facebook Plugin Dir ~/catchgirl/plugins/facebook plugins/facebook/__init__.py
Extend GAEO Controller Mix BaseContoller with plugin class. Class LazyController: def render_json(self, obj):  self.render(self.to_json(obj)) from gaeo.controller import BaseController BaseController.__bases__ += (LazyController,) After plugin loaded. BaseController has the render_json method it does not have before.
Extend GAEO Model BaseModel can mix also. Class LazyModel: @classmethod def get_by_gameid(cls, id): obj = cls.gql(&quot;WHERE game_id =&quot;+str(id)+&quot; \ ORDER BY lastupdate_at&quot;).get() return obj from gaeo.controller import BaseController BaseModel.__bases__ += (LazyModel,) BaseModel has get_by_gameid method now.
Mixing? What is it meaning?
七龍珠
合體
貝吉特   +   特南克斯   = ?
貝吉特南克斯 戰力指數 ++ 還是被打掛…
Class  合體 指揮艦組合
當然也是 戰力指數 ++ 這次絕對不會掛
Mix two class or more. Class Man: def love_woman() retrun true Class Woman: def love_man() retrun true Class Bat def fly() retrun true Man().love_man() Method not exists! Man.__bases__ += (Woman,) Man().love_woman() = true Man().love_man() = true Man.__bases__ += (Bat) Man().love_woman() = true Man().love_man() = true Man().fly() = true
How does mixin work in gaeo plugin Child class get method/attributes from its father 張無忌從謝遜身上習得七傷拳 Mixin father class with plugin class == Child class has new grandfather, and also has new feture from grandfather. 謝遜認韋小葆為乾爹,韋小葆以抓奶龍爪手聞名江湖 張無忌從謝遜身上習得七傷拳,抓奶龍爪手… 謝遜認柯珂科為乾爹,柯珂科以抓奶龍爪手聞名江湖 張無忌從謝遜身上習得七傷拳,抓奶龍爪手 , 還我漂漂拳
GAEO Management Tools Start new project quickly
Create Project Create project gaeo.py newporject Create prject with Eclipse config gaeo.py –eclipse newproject
Create Model Command $ gaeogen.py model money bank user Will create /project/application/model/money .py /project/application/model/bank .py /project/application/model/user.py from google.appengine.ext import db  from gaeo.model import BaseModel class Money(BaseModel): pass
Create Contorller Command $ gaeogen.py controller money show add edit Will create /project/application/controller/money.py project/application/template/add.html project/application/template/edit.html project/application/template/edit.html from gaeo.controller import BaseController  class WelcomeController(BaseController): def show(self): Pass def add(self): Pass def edit(self): pass
Create scaffold GAEO has scaffold also, but I never use it, becuse I wrote most common controller method in my plugin, called as lazycontroller. Lazycontroller has new_or_edit - create a model or edit it. implement edit and new  in subclass. create – do create model update – do update model _storage -  storage the data to datastore. implement _mk_attrs in subclass.
結論
小 Others all all too big, too complex
易 因為小,所以目前只有一些基礎功能
請愛用國貨,促進經濟發展 如果要寫GAE,我一定用GAEO 因為其它的都需要花 不少的時間學習
GAEO == Python On Rails? Remove google app engine depency in my wish list.
You Can Help GAEO Better Improvent GAEO,  write totrial , develope Plugin and more
Refrence/Contact Officail Web Site http://www.gaeo.org   Officail Document Web Site http://doc.gaeo.org  (english) http://doc-zhtw.gaeo.org/   (traditional chinese) http://doc-fr.gaeo.org/   (french) Erisck's Blog Http://a.b.org   GAEO Plugins Web Site http://plugins.gaeo.org   GAEO Soruce Code Repositry http://code.google.com/gaeo/   GAEO Google Grouphttp://groups.google.com/group/google-app-engine-oil?hl=en IRC Server: irc.freenode.net Channel: #gaeo, #tossug Google App Engine http://code.google.com/appengine/
The End Any qutions?

GAEO

  • 1.
    陳信屹 HsinYi, Chen Hychen (usually use in internet) Let's Start GAEO 2008/12 /20 Kalug metting A web framwork. [email_address] [email_address] http://hychen.wuweig.org
  • 2.
  • 3.
    但是有些事 我 們不 想 處 理 Web server 哪個 好 ? Db 要 用哪 一種 ? 記憶 體又 爛 了 網路 又斷了, 該死 的 種花電信 這樣 我 投影片 怎麼作 ? email 又 寄不出去 又 被 XXX 當 廣告信 不 是 正妹 的 電腦 我 不想 修 理 很 我 懶 很 我 懶
  • 4.
    Python 我們需要一個solution Goggle App Engine 好像不錯 ? 免費 免費 免費
  • 5.
  • 6.
    但是有人覺得 Google 這台引擎 不太順 ....
  • 7.
  • 8.
    Google App EngineOil Hi, I am Erisck GAEO( 尬意喔 ) Google App Engien Oil 作者 Erisck ver 0.2, since 2008 Web Framwork 台灣製造 這個油絕對不會 漲價 Erisck
  • 9.
    Model Use GoogleApp Engine Datastore API Model Relation Mapper Many To One: belonss_to() Many To Many: Not Implment yet (0.2 release) Has useful attributes updates method. model_obj.update_attributes(name='hi') model_obj.update_attributes({name:'hi'})
  • 10.
    So, GAEO IsAlso MVC Model / Controller / View
  • 11.
    GAEO is aMVC Framwork Model GAE Datastore Model Controller POST/GET/PUT/DELETE View XML/HTML/JSON/TEXT/IMAGE HTML Template Engine Django Template
  • 12.
  • 13.
    http://example.org/home Which controller ? Which action ?
  • 14.
    Original GAE URlRouting Django like app.yaml urls.py in django Regex supported Easy config? Easy understand? I don't know handlers: - url: /css static_dir: assets/css - url: /js static_dir: assets/js
  • 15.
    GAEO URL RoutingRails lik main.py Regex supported Easy understand Easy config It's more eazy than orginal configure to me r.connect('/about/', \ controller='welcome', \ action=&quot;about&quot;) # http://example.org/welcome/ \ about r.connect('/:controller/:action/:id') # http//example.org/ctrl/act/1
  • 16.
  • 17.
    Controller Do actionto render View
  • 18.
    How to getdata from GET/POST PHP $_GET['缺']; $_POST[''錢”]; GAEO GET/POST datas are all in self.params variable Class LifeController(BaseController): def need_money(self): print self.params['缺'] print self.params['錢']
  • 19.
    Get params http://example.org/welcome/about/xFjddeYClass WelcomeController(BaseController): def aboutz(self): self.params = {'id':'xFjddeY'} http://example.org/welcome/about/?user=1&is_guest=y Class WelcomeController(BaseController): def aboutz(self): self.params = {'id':'':,'user':1,'is_guest':'y'}
  • 20.
    How to storagedata in session? Implement by GAE memcache. PHP $_SESSION['正妹'] = &quot;國字臉才叫正” GAEO Class GirlController(BaseController): def catch(self): self.session['正妹'] = ”國字臉才叫正” self.session['正妹'].put()
  • 21.
    推 Remember PUT 倒 self.session[' 正妹 '].put()
  • 22.
    How to getdata from session? PHP echo $_SESSION['正妹們'] GAEO Class GirlController(BaseController): def catched_list(self): print self.session['正妹們']
  • 23.
    How to storagedata in cookie? PHP $_COOKIE[' 阿宅說 '] = &quot; 有 MSN 也沒用,我不敢跟女生說話” $_COOKIE[' 標準答案 '] = &quot;MSN ID 都是中性的 , 在 XX 之前把他當人妖” set_cookie() GAEO Class AJaiController(BaseController): def show_anwser(self): self.cookie[' 阿宅說 '] = .... self.cookie[' 阿宅說 '] = ....
  • 24.
    How to getdatas from cookie? PHP echo $_COOKIE['大宅門'] GAEO Class GirlController(BaseController): def be_master(self): print self.cookie['大宅門'] # !!! KeyError: '大宅門'
  • 25.
    But How toSet Expier time?
  • 26.
    404 Not Found
  • 27.
  • 28.
  • 29.
    How to getrequest Class Controller: def __demo__(self): self.request
  • 30.
    View HTML /XML / JSON / More Wait! How to use template engine in GAEO?
  • 31.
    Render HTML DjangoTemplate Markup Controller attribute be template variable automaticlly __dict__ Class CatchController(...): def show(self): self.viewer = {'name':' 正妹 ', ''age”:18} /project/applications/templates/catch/show .html <h1>{{viewer.name}}</h2> {{self.request}} {{self.params}}
  • 32.
    Render Json ClassController: def render_json(self): self.render(json=self.to_json({'1':'1'})
  • 33.
    Render XML Googleapp engine model can convert to xml Class Controller: def render_xml(self): xml_content = model_obj.to_xml() self.render(xml=self.to_xml(xml_content)
  • 34.
    Plugin Every applicationhas its plugin architecture...
  • 35.
    GAEO Plugin Saveyour time! You/Other people can write a plugin to Extends BaseController class Extends BaseModel class Extends GAEO more powerful! Help web app developement quickly and easir. Ok, It looks more like Rails.... Collection site: http://plugins.gaeo.org plugins are very few now... we need yours!
  • 36.
    How does pluginwork? All plugins are saved in $project/plugins Init function in main.py Load before the application started. All magic are in the file Project root ~/catchgirl/ Project Plugins Dir ~/catchgirl/plugins/ Facebook Plugin Dir ~/catchgirl/plugins/facebook plugins/facebook/__init__.py
  • 37.
    Extend GAEO ControllerMix BaseContoller with plugin class. Class LazyController: def render_json(self, obj): self.render(self.to_json(obj)) from gaeo.controller import BaseController BaseController.__bases__ += (LazyController,) After plugin loaded. BaseController has the render_json method it does not have before.
  • 38.
    Extend GAEO ModelBaseModel can mix also. Class LazyModel: @classmethod def get_by_gameid(cls, id): obj = cls.gql(&quot;WHERE game_id =&quot;+str(id)+&quot; \ ORDER BY lastupdate_at&quot;).get() return obj from gaeo.controller import BaseController BaseModel.__bases__ += (LazyModel,) BaseModel has get_by_gameid method now.
  • 39.
    Mixing? What isit meaning?
  • 40.
  • 41.
  • 42.
    貝吉特 + 特南克斯 = ?
  • 43.
  • 44.
    Class 合體指揮艦組合
  • 45.
    當然也是 戰力指數 ++這次絕對不會掛
  • 46.
    Mix two classor more. Class Man: def love_woman() retrun true Class Woman: def love_man() retrun true Class Bat def fly() retrun true Man().love_man() Method not exists! Man.__bases__ += (Woman,) Man().love_woman() = true Man().love_man() = true Man.__bases__ += (Bat) Man().love_woman() = true Man().love_man() = true Man().fly() = true
  • 47.
    How does mixinwork in gaeo plugin Child class get method/attributes from its father 張無忌從謝遜身上習得七傷拳 Mixin father class with plugin class == Child class has new grandfather, and also has new feture from grandfather. 謝遜認韋小葆為乾爹,韋小葆以抓奶龍爪手聞名江湖 張無忌從謝遜身上習得七傷拳,抓奶龍爪手… 謝遜認柯珂科為乾爹,柯珂科以抓奶龍爪手聞名江湖 張無忌從謝遜身上習得七傷拳,抓奶龍爪手 , 還我漂漂拳
  • 48.
    GAEO Management ToolsStart new project quickly
  • 49.
    Create Project Createproject gaeo.py newporject Create prject with Eclipse config gaeo.py –eclipse newproject
  • 50.
    Create Model Command$ gaeogen.py model money bank user Will create /project/application/model/money .py /project/application/model/bank .py /project/application/model/user.py from google.appengine.ext import db from gaeo.model import BaseModel class Money(BaseModel): pass
  • 51.
    Create Contorller Command$ gaeogen.py controller money show add edit Will create /project/application/controller/money.py project/application/template/add.html project/application/template/edit.html project/application/template/edit.html from gaeo.controller import BaseController class WelcomeController(BaseController): def show(self): Pass def add(self): Pass def edit(self): pass
  • 52.
    Create scaffold GAEOhas scaffold also, but I never use it, becuse I wrote most common controller method in my plugin, called as lazycontroller. Lazycontroller has new_or_edit - create a model or edit it. implement edit and new in subclass. create – do create model update – do update model _storage - storage the data to datastore. implement _mk_attrs in subclass.
  • 53.
  • 54.
    小 Others allall too big, too complex
  • 55.
  • 56.
  • 57.
    GAEO == PythonOn Rails? Remove google app engine depency in my wish list.
  • 58.
    You Can HelpGAEO Better Improvent GAEO, write totrial , develope Plugin and more
  • 59.
    Refrence/Contact Officail WebSite http://www.gaeo.org Officail Document Web Site http://doc.gaeo.org (english) http://doc-zhtw.gaeo.org/ (traditional chinese) http://doc-fr.gaeo.org/ (french) Erisck's Blog Http://a.b.org GAEO Plugins Web Site http://plugins.gaeo.org GAEO Soruce Code Repositry http://code.google.com/gaeo/ GAEO Google Grouphttp://groups.google.com/group/google-app-engine-oil?hl=en IRC Server: irc.freenode.net Channel: #gaeo, #tossug Google App Engine http://code.google.com/appengine/
  • 60.
    The End Anyqutions?