Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Grok in Plone

1 842 vues

Publié le

These are the slides for the talk I gave at the PloneSA group meeting in Cape Town on Wednesday 6 July 2011

Publié dans : Technologie

Grok in Plone

  1. 1. Using Grok in Plone with Five.Grok <ul><li>JC Brand
  2. 2. [email_address]
  3. 3. http://opkode.com </li></ul>
  4. 4. What is Grok? <ul><li>Web application framework built on Zope 3 </li><ul><li>Inspired by Ruby on Rails </li><ul><li>Convention over configuration
  5. 5. Don't repeat yourself </li></ul><li>Aims avoid the need for ZCML </li></ul><li>http://grok.zope.org </li></ul>
  6. 6. What is Grok? <ul><li>Both Grok/Plone uses Zope Toolkit (ZTK)
  7. 7. ZTK uses Zope Component Architecture (ZCA)
  8. 8. ZCA also used by Pyramid/Pylons
  9. 9. Distinguishing Grok features (also in Plone): </li><ul><li>Component Architecture (ZCA)
  10. 10. Object Database (ZODB)
  11. 11. Object publishing and traversal </li></ul></ul>
  12. 12. Zope Component Architecture <ul><li>Allows developers to create reusable components
  13. 13. Components are objects with Interfaces
  14. 14. Many-to-one mapping between objs and Interfaces, can be interchanged.
  15. 15. ZCA has roughly 2 kinds of components: </li><ul><li>Adapters extend other components or models/content types.
  16. 16. Utilities, standalone (config, db connect, mail etc.) </li></ul><li>ZCA allows extending 3rd party code without direct/edit access to it </li></ul>
  17. 17. Grok does away with ZCML <ul><li>In ”plain” Zope, developer writes component in Python and registers it for ZCA in ZCML.
  18. 18. ZCML = glue or wiring
  19. 19. Grok lets you use python statements instead of ZCML
  20. 20. Keeps glue and code together
  21. 21. Makes it easier to see what registrations are in effect
  22. 22. Reduces need to context switch files/syntaxes </li></ul>
  23. 23. Using Five.Grok in Plone <ul><li>BrowserViews </li><ul><li>Common display technology in Zope
  24. 24. In use in Plone, BlueBream, Grok, Pyramid
  25. 25. BrowserView is a multi-adapter (i.e ZCA component)
  26. 26. Python class containing ”display logic”, registered as a multi-adapter for Request and content-type.
  27. 27. Normally has template, but not required (i.e Ajax)
  28. 28. Doesn't always return anything (i.e redirects)
  29. 29. See: plonesa.grok/browser/* </li></ul></ul>
  30. 30. Using Five.Grok in Plone <ul><li>Adapters </li><ul><li>Most powerful concept of ZCA
  31. 31. Adapts an object of specific Interface, to also provide functionality specified by the adapter's interface.
  32. 32. Analogous to Type Casting
  33. 33. Real world analogy: Wall plug adapters
  34. 34. plonesa/grok/adapter.py </li></ul></ul>
  35. 35. Using Five.Grok in Plone <ul><li>Viewlets </li><ul><li>Snippets of reusable HTML for rendering as part of a page (not the whole page).
  36. 36. Similarities with BrowserViews
  37. 37. Render inside ViewletManagers
  38. 38. plonesa/grok/browser/viewlet.py </li></ul></ul>
  39. 39. Event subscribers <ul><li>Event subscribers </li><ul><li>Also called event listeners
  40. 40. Zope provides an events system
  41. 41. Components notify the subscribers of a particular event.
  42. 42. Code execution is blocked until all subscribers are done.
  43. 43. plonesa/grok/events.py </li></ul></ul>
  44. 44. Other Five.Grok functionality <ul><li>Annotations </li><ul><li>Grok's Annotations are Adapters with attributes that persist (i.e can be stored).
  45. 45. Plone uses IAnnotations from zope.annotation which has a dict-like API.
  46. 46. Grok's pattern can cause problems when code is moved or uninstalled (which happens often in Plone)
  47. 47. http://pypi.python.org/pypi/grokcore.annotation </li></ul></ul>
  48. 48. Other Five.Grok functionality <ul><li>Defining Permissions </li><ul><li>Grok uses grok.Permission
  49. 49. In Plone we define permissions in GS-XML configuration files rather than code.
  50. 50. See: http://pypi.python.org/pypi/grokcore.security </li></ul><li>Utilities </li><ul><li>Global (Zope-wide) or local utilities (Plone or folder-wide)
  51. 51. For local, Grok uses grokcore.site
  52. 52. In Plone we use componentregistry.xml GS-XML </li></ul></ul>
  53. 53. Other Five.Grok functionality <ul><li>Resource directories </li><ul><li>Grok has an implicit static directory
  54. 54. Can also use grok.DirectoryResource instead of <browser.resourceDirectory/> directive.
  55. 55. See http://pypi.python.org/pypi/grokcore.view </li></ul></ul>
  56. 56. Other Five.Grok functionality <ul><li>Browser Layers </li><ul><li>Can use grok.skin()
  57. 57. In Plone we use browserlayer.xml in GenericSetup
  58. 58. Alternatively SkinLayers via plone.theme package and configure.zcml </li></ul></ul>
  59. 59. Other Five.Grok functionality <ul><li>Forms </li><ul><li>Grok uses grokcore.formlib </li><ul><li>Megrok.z3cform </li></ul><li>Plone still uses/supports formlib but momentum is moving towards z3c.form (i.e Dexterity ) </li><ul><li>collective.z3cform.grok </li></ul></ul></ul>
  60. 60. Other Five.Grok functionality <ul><li>Content Types </li><ul><li>Grok uses grok.Model
  61. 61. Plone uses Dexterity and Archetypes </li></ul><li>Ordering Viewlets </li><ul><li>Grok uses g rok.order() to order viewlets based on integer weighting.
  62. 62. Plone uses plone.app.viewletmanager and GS-XML instead. </li></ul></ul>
  63. 63. Other Five.Grok functionality <ul><li>Static resources dir </li><ul><li>Grok has a special dir static for static resources (JS and CSS)
  64. 64. Can be accessed via TAL: view/static/stylesheet.css
  65. 65. In Plone this will always be relative to the context, rather than relative to site navigation root, which means it doesn't cache well.
  66. 66. Construct URL manually instead.
  67. 67. See: http://pypi.python.org/pypi/grokcore.view </li></ul></ul>
  68. 68. Thanks and Credits <ul><li>Carlos de la Guardia </li><ul><li>Grok 1.0 Web Development
  69. 69. http://bit.ly/lf7sci </li></ul><li>Martin Aspeli </li><ul><li>http://bit.ly/iyESUB </li></ul></ul>