Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

GAEO

3,053 views

Published on

GAEO talk in kalug.

Published in: Technology
  • Be the first to comment

GAEO

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

×