Create Book' Link = 'Mkbook' Mclass = 'Nav Buttons'

Create Book' Link = 'Mkbook' Mclass = 'Nav Buttons'

Grok 4 Noobs. P R Sephton Grok 4 Noobs. A gentle introduction to using the Grok web framework 2 A gentle introduction to using the Grok web framework Table of Contents: 1: What does Grok do particularly well? ... [7] 1.1: What are the nicest things about Zope & Grok? ... [10] 2: Grok & Zope in a Nutshell ... [13] 3: The Compulsory Part about Installing Grok ... [19] 3.1: Installing Grok from Github ... [21] 3.2: Installation Notes - older projects ... [22] 4: A short introduction to the Zope Component Architecture ... [24] 4.1: The Z-Object Publishing Environment ... [29] 4.2: Interfaces compared to Abstract Bases ... [30] 4.2.1: Interfaces vs. Inheritence: A Real World Example ... [33] 4.3: Traversal and the Context ... [39] 4.4: The amazingly useful Utility ... [41] 4.5: Events Mechanism ... [42] 4.5.1: A quick megrok.rdb (SQLAlchemy) setup howto ... [44] 4.6: Extending existing objects with Annotations ... [46] 5: Designing a site, defining it's layout and implementing the code ... [47] 5.1: How to make applications with Grok ... [49] 5.1.1: Modeling data in an application ... [53] 5.1.1.1: Notes on multithreading ... [55] 5.1.1.2: The Scope of models in Traversal ... [57] 5.1.1.3: Rules of Persistence ... [58] 5.1.1.4: User Session Management ... [59] 5.1.2: Defining an Article and the Application ... [60] 5.1.3: HTML Re-use and site layout ... [62] 5.1.3.1: Macros: an alternative way to re-use HTML ... [67] 5.1.3.2: The full source for the layout.py module ... [69] 5.1.4: Providing for article addition, modification and deletion ... [72] 5.1.4.1: Another way of rendering hidden input widgets ... [77] 5.1.5: Using Viewlets and Viewlet Managers to build a Navigation Fabric ... [79] 5.1.5.1: Ordered menus from a normal grok.Container ... [83] 5.1.5.1.1: Full source for SortedArticles Module ... [88] 5.1.5.2: menu.py Full Source ... [92] 5.1.5.3: Styling menu elements as buttons or menus ... [94] 5.1.6: Site Navigation: Context sensitive menus ... [97] 5.1.7: Integrating the tinyMCE editor ... [100] 5.1.7.1: A less trivial integration for tinyMCE ... [101] 5.1.8: Adding attachments to articles ... [104] 5.1.8.1: Adding syntax highlighting ... [115] 5.1.9: Authentication, Authorisation and Access Control ... [117] 5.1.9.1: Defining erP missions ... [119] 5.1.9.2: Defining and Assigning olesR ... [121] 5.1.9.3: Installing a Pluggable Authentication Utility ... [122] 5.1.9.4: Building a user management interface ... [128] 5.1.9.5: Controlling access to views and data ... [135] 6: Adding functions and extensions ... [137] 6.1: Adding an Index Page ... [138] 6.2: Printing the site as a book ... [141] 6.3: Using Layers and Skins: How to re-skin your Grok site ... [145] 6.3.1: Using Bootstrap to fast track site development ... [146] 6.3.2: Providing a nav bar and breadcrumbs ... [148] 6.3.3: Some closing remarks ... [152] 6.4: Adding a Disqus comment section ... [153] 7: About ... [155] 8: Other Resources available on the web ... [156] 3 Grok 4 Noobs. Grok is a web framework based upon the Zope Toolkit [1] (ZTK) and the Zope Component Architecture [2] (ZCA). Development for this framework began in 2006, with the view to making Zope-3 technology more accessible to newcomers. It achieves this quite admirably by using a mix of convention, special Grok directives, and decorators to make the task of building and maintaining web sites really simple. A Little History At one time Zope-2 [3] was the darling of the Python web development world. Zope-2 was based on a Through the Web (TTW) development model, which meant that developers could collaborate and program a Zope-2 installation remotely. It was fast (really fast and efficient for its time), simple, intuitive and had a large number of building blocks. To this day, Zope-2 remains popular as the basis for the Plone-3 CMS. Zope-3, these days called BlueBream [4], was intended to be a replacement for Zope-2, but this didn't quite work out as planned. As fast as features were added to Zope-3, they were back-ported to Zope-2 in a compatibility library called "Five" (5 = 2 + 3). This reduced and hampered motivation for adopting the newer Zope-3 in favor of Zope-2. At the same time, Ruby and Rails [5] happened which completely reimagined the way people viewed web frameworks. Django and other Python frameworks sprang up and quickly gained popularity as Python programmers began to realise that Python web development didn't have to be a ghastly chore. The Pyramid web framework [6] came about as an effort to make Zope technologies more accessible and less intimidating to newcomers. Grok happened at around the same time and shared many of the same motives. Zope-2 popularised and was popularised by TTW (Through the Web) development, but Zope-3, as was the case for most of the other Python frameworks, was not a TTW framework. The promise of TTW development was that anyone, not just developers, could develop web sites by adding new, or stringing together pre-defined web components online, often never having to write a line of actual code. Today, popular site builders such as WIX or Weebly or tools like WordPress accomplish that vision. It was arguably the confusion surrounding what Zope actually is, which brought about all of the misunderstanding, most of the confusion and much of the criticism surrounding the product. The mistake of Zope was mostly one of branding. Zope 4 development began more recently, and is a project to build a new TTW web platform with all the bells and whistles originally found in Zope 2. The advances made in 1. The Zope Toolkit API: http://docs.zope.org/zopetoolkit/ 2. ZCA Book: http://muthukadan.net/docs/zca.html 3. The zope-2 home page: http://zope2.zope.org/ 4. Bluebream Framework: http://bluebream.zope.org/ 5. Ruby on Rails: https://rubyonrails.org/ 6. Pyramid: https://trypyramid.com/ 4 A gentle introduction to using the Grok web framework the Zope Toolkit are brought forward into Zope 4, and the new platform contains many new and exciting features. So why is Grok important? Grok is quite possibly the best way to make use of the over 15 years of accumulated intellectual capital which comprises the Zope Toolkit (ZTK) libraries. It is open and accessible, and its seamless use of the Zope Component Architecture (ZCA) is intuitive and simple. Although BlueBream exists, along with it's amazingly complete set of documentation and thoroughly tested code, the same reasons why people migrated away from Zope-3 in the first place persist today. When the configuration for components is maintained in ZCML, separate from their definition and implementation, this separation can lead to unnecessary complexity and poor maintainability. ZCML was a particularly unpopular idea, and it is unlikely that anyone would want to, nor is it entirely advisable at this stage to adopt the BlueBream framework for new projects. Pyramid was, at least initially, also based upon the Zope Toolkit. However, Pyramid takes the approach of wrapping and hiding the component architecture (ZCA) from it's users, and there is not much recognisable left of the original architecture. It tries hard to be a generalised solution for all your needs, and succeeds at this in many ways. Grok, on the other hand is very different. With an initial investment of a few weeks (depending on learning speed) to properly understand how to fully exploit the Zope Component Architecture (ZCA), Grok gives you a mature and well documented framework capable of delivering relatively complex products in comparatively very little time. What's this site all about? This site documents it's own implementation. All source code is freely available on the web [1], and may be used to recreate instances of this site or to explore concepts and ideas around the Grok web framework. To demonstrate the flexibility, utility and extensibility of Grok, this wiki uses the built in object database (ZODB) to store editable articles which describe the site itself. From the database, we can later produce a dynamic index, or a printable book. This site may not be perfect in every way, but it does serve its purpose in showing how a Grok site may be developed modularly using pluggable and reusable components for things like authentication, layout, menus, HTML editors and even skinning an existing site using Bootstrap [2] or adding Disqus [3] for comments and feedback. The Grok tutorial [4] does a great job at showing off the simplicity of the framework. It is unfortunately not so good at showing how to progress beyond the simple things, or how the ZCA can help you build great sites quickly and maintainably instead of being the millstone around everyone's necks they imagine it to be. The ZCA is the elephant in the 1. Source code for this site: https://github.com/prsephton/Grok4Noobs 2. Bootstrap: https://getbootstrap.com/ 3. Disqus: https://disqus.com/ 4. The Grok Tutorial: http://grok.zope.org/doc/current/tutorial.html 5 Grok 4 Noobs. room everyone is ignoring which, rather than being treated like the embarrasing relative, should be the first thing proudly introduced to newcomers. In many ways, Grok's choice of a (very cute) cave man as an emblem is so very wrong. Whilst one understands the humour of man with a club smashing obstacles like ZCML, the overriding association created in peoples fertile imaginations is undoubtedly that Grok, like cavemen, is a relic of a prehistoric age, working with ancient libraries and technologies.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    156 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us