Grok 1.0 Web Development

Grok 1.0 Web Development
eBook: $23.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $63.98    Print cover: $39.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Develop efficient and powerful web applications and web sites from start to finish using Grok, which is based on Zope 3
  • Integrate your applications or web sites with relational databases easily
  • Extend your applications using the power of the Zope Toolkit
  • Easy-to-follow and packed with practical, working code with clear explanations

Book Details

Language : English
Paperback : 308 pages [ 235mm x 191mm ]
Release Date : February 2010
ISBN : 1847197485
ISBN 13 : 9781847197481
Author(s) : Carlos de la Guardia
Topics and Technologies : All Books, Web Development, Open Source, Python, Web Development

Table of Contents

Chapter 1: Getting to Know Grok
Chapter 2: Getting Started with Grok
Chapter 3: Views
Chapter 4: Models
Chapter 5: Forms
Chapter 6: The Catalog: An Object-Oriented Search Engine
Chapter 7: Security
Chapter 8: Application Presentation and Page Layout
Chapter 9: Grok and the ZODB
Chapter 10: Grok and Relational Databases
Chapter 11: Key Concepts Behind Grok
Chapter 12: Grokkers, Martian, and Agile Configuration
Chapter 13: Testing and Debugging
Chapter 14: Deployment
  • Chapter 1: Getting to Know Grok
    • Why Grok?
    • Distinguishing Grok concepts
      • The Zope Component Architecture
      • Object database
      • Object publishing and traversal
    • Other Grok features
      • Integrated security model
      • Easy use of existing Python libraries and modules
      • Static resources
      • Relational database access
      • Python Web Server Gateway Interface compatibility
    • How Grok compares to other web frameworks
      • PHP
      • Java frameworks
      • Ruby on Rails
      • Django
      • Pylons
    • Summary
  • Chapter 2: Getting Started with Grok
    • Getting a C compiler
    • Installing Python
      • Installing Python on Unix/Linux
      • Installing Python on Mac OS X
      • Installing Python on Windows
    • EasyInstall and the Python Package Index (PyPI)
    • Grok and the Python environment
    • Virtualenv
      • Installing Grok using grokproject
      • Creating our first project
      • Running the default application
    • What's inside a Grok project?
      • Overview of the application structure
      • Creating our first template
    • The Grok admin UI
      • Applications
      • Server control
      • Documentation
    • Summary
  • Chapter 3: Views
    • Grok views
    • Zope Page Templates (ZPT)
      • The Template Attribute Language (TAL)
      • Expression types
      • Inserting text
      • Repeating tags
      • Conditional elements
      • Variables
      • Special variables
      • Modifying HTML tag attributes
      • Inserting structure
      • Multiple statements in one tag
      • Macros and slots
      • Going beyond ZPT basics
    • The to-do list application
    • Handling form data
    • Adding static resources
    • Putting in some JavaScript flourish
    • Summary
  • Chapter 4: Models
    • Models and applications
    • Storing model data
      • The ZODB
      • Changing the title dynamically
      • The rules of persistence
    • Display logic and application logic
      • Separating display and application logic
    • Using containers and multiple models
      • Adding containers to our application
      • Adding behavior to the models
      • The TodoList model
      • Reorganizing the views
      • Introducing class annotations
      • Setting view names explicitly
      • Redirecting views
    • The Grok introspector
    • Summary
  • Chapter 5: Forms
    • A quick demonstration of automatic forms
    • Interfaces
      • Example of an interface
      • Interfaces in Grok
    • Schemas
      • Available schema attributes and field types
    • Form fields and widgets
    • Form components
      • Adding a project container at the root of the site
      • Form actions
      • Trying out the application
    • Filtering fields
    • Using grok.EditForm
    • Modifying individual form fields
    • Form validation
    • Customizing the form template
    • Summary
  • Chapter 6: The Catalog: An Object-Oriented Search Engine
    • Catalogs and indexes
    • Adding a simple search function to the application
      • Defining a simple index
      • Creating the search view
      • Creating a template to display the search results
    • A brief diversion: Structuring our application for search
    • Back to search: Using multiple indexes
    • Indexing different kinds of objects
    • The catalog admin UI
    • Types of indexes
    • Summary
  • Chapter 7: Security
    • Authentication and authorization
    • Principals, permissions, and roles
    • Security policies
      • Default Grok security policy definition
      • Modifying the security policy
        • Modifying the default view permissions
        • Adding a new user
        • Protecting a view
    • Setting up a custom security policy
      • Creating permissions
      • Roles
    • Adding authentication
      • The Pluggable Authentication Utility
      • Registering PAU with our application
      • Adding a credentials plugin
        • The login form
        • The logout view
      • The UserAuthenticator plugin
        • Adding users
        • Basic user management
    • Summary
  • Chapter 8: Application Presentation and Page Layout
    • Viewlets and viewlet managers
      • Viewlets
      • Viewlet managers
    • Understanding how the pieces fit together
      • View methods and attributes
      • Viewlet methods and attributes
      • Viewlet manager methods and attributes
    • To-do list manager layout
      • Defining viewlet managers in application code
      • Registering viewlets
      • Modifying existing views to use the master template
      • Inserting forms into viewlets
      • Using viewlets to insert different static resources
    • Layers and skins
      • Skins in Grok
    • Adding themes to our application
      • Overriding a viewlet
      • Using the new skins
    • Summary
  • Chapter 9: Grok and the ZODB
    • How the ZODB works
      • Transparency
      • ACID properties
      • Other ZODB features
      • ZEO
    • Using the ZODB
      • The rules of persistence
      • Traversal
      • How Grok uses the ZODB
    • Adding Blob support to our application
      • Adding messages to projects
        • The megrok.form package
        • Adding an external package to our project
        • How blob support is configured in Grok
        • The messaging class and schema
        • The message viewlet
        • The message list template
        • Downloading an attachment
        • Testing the Blob support
    • Taking advantage of transactions
      • Using
      • Testing the undo functionality
    • ZODB maintenance
      • File storage
      • Automatic packing
      • Backing up
      • Using the ZODB without Grok
    • Summary
  • Chapter 10: Grok and Relational Databases
    • Object Relational Mappers
      • SQLAlchemy
      • Including SQLAlchemy in our Grok project
        • Using SQLAlchemy
    • Using a relational database for authentication
    • Handling database transactions securely
    • Creating database-backed models and containers
      • The megrok.rdb package
      • Making an application database backed
    • When to use the ZODB versus a relational database
    • Summary
  • Chapter 11: Key Concepts Behind Grok
    • The Zope Component Architecture
      • Interfaces
      • Adapters
        • Real-world adapters
        • Defining and using an adapter
        • Adapters that we have used in our application
      • Utilities
        • Global utilities
        • Local utilities
      • Events
    • Extending a Grok application from the outside
      • Preparing the original application
      • The to-do plus package
        • Creating the new package
      • Adding a skin chooser form to the application
        • Adding a new skin
        • The skin chooser form
        • Using events to show the selected skin
      • Sending e-mail notifications on content creation
        • Object annotations
        • Creating the form
        • Sending the e-mail
      • Displaying additional navigation links
    • Summary
  • Chapter 12: Grokkers, Martian, and Agile Configuration
    • Agile configuration
    • The Martian library
    • Understanding grokkers
      • The grokked class
      • The directives
      • The class grokker
      • The only ZCML you'll ever need
    • Creating our own grokker for zope.sendmail configuration
      • Creating the package
      • Writing our grokker
      • Using mailgrokker
    • Summary
  • Chapter 13: Testing and Debugging
    • Testing
      • Unit testing
      • Functional tests
    • Testing in Grok
      • Doctests
      • Default test setup for Grok projects
        • Test configuration
        • Test files
        • Running the tests
      • The test runner
        • Test layers
        • Invoking the test runner
      • Looking at the test code
        • ftesting.zcml
        • app.txt
      • Adding our own tests
        • The Browser class
        • Our first to-do application tests
        • Adding unit tests
        • Extending the test suite
    • Debugging
      • Debugging in Grok
        • The default Ajax debugger
        • Post-mortem debugging with the Python debugger
    • Summary
  • Chapter 14: Deployment
    • Moving an application to production mode
    • Running the paster server in the background
    • Running Grok behind the Apache web server
      • Using mod_rewrite to serve our application from Apache
      • Installing and setting up Grok under mod_wsgi
        • WSGI: The Python Web Server Gateway Interface
        • Grok and WSGI
        • Why use Apache and mod_wsgi for Grok?
        • Setting up a clean Linux server
        • Installing and configuring mod_wsgi
        • Configuring a Grok site under mod_wsgi
        • Getting the to-do application ready for mod_wsgi
        • Configuring an Apache site to use mod_wsgi
        • Running the application
      • Adding a ZEO server
        • Buildout recipe for the ZEO configuration
        • Configuring the ZEO client
        • Launching the ZEO server
        • Augmenting the number of processes
    • More scalability: Adding caching and load balancing
      • Caching proxies
      • Load balancers
      • A high-traffic architecture for Grok
    • Summary

Carlos de la Guardia

Carlos has been doing web consulting and development since 1994, when selling any kind of project required two meetings just to explain what the Internet was in the first place. He was the co-founder of Aldea Systems, a web consulting company where he spent ten years working in all kinds of web projects using a diverse range of languages and tools. In 2005 he became an independent developer and consultant, specializing in Zope and Plone projects. He frequently blogs about Plone and other Zope-related subjects.

Code Downloads

Download the code and support files for this book.

Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


- 11 submitted: last submission 18 Oct 2013

Errata type: Technical| Page number: 21 |

The last command on the page: # virtualenv --no-site-packages–no-site-packages–no-site-packages testgrok should be: # virtualenv --no-site-packages testgrok


Errata type: Technical | Page number: 23 |

Note: Sometimes, grokproject may fail during install due to external factors, such as a bad internet connection. When this happens, you might end up with a broken installation. To fix this, run the bin\buildout.exe script from the top directory of the installation


Errata type: Technical | Page number: 13 |

TA designer using a WYSIWYG tool will see the words "A simple multiplication" should be: A designer using a WYSIWYG tool will see the words "Me Grok can multiply"


Errata type: Technical | Page number: 36 |

Description: The name of the list of weapons should be 'weapons' instead of 'weapon'. This affects two sentences: 1) To see how it works, suppose that we have a list of weapons that is passed to the template as an attribute of the view, with the name weapon: should be To see how it works, suppose that we have a list of weapons that is passed to the template as an attribute of the view, with the name weapons: 2) If weapon contains the list ['Rock','Club','Spear'], the template will be rendered like this: should be: If weapons contains the list ['Rock','Club','Spear'], the template will be rendered like this:


Errata type: Technical | Page number: 13 |

The line "bin/paster serve etc/deploy.ini" should read "bin/paster serve parts/etc/deploy.ini" instead.


Errata type: Technical| Page number: 48 |

Second block of code, third line: tal:attributes="name string:item_{repeat/item/index}; should contain a $-sign: tal:attributes="name string:item_${repeat/item/index}; php


Errata type: Technical | Page number: 54 |

The 10th line: string:delete_${rep eat/item/index}; should be: string:delete_${repeat/item/index}; The 19th line: name="item_description"> should be: name="item_description"/>


Errata type: Technical | Page number: 65 |

The 4th line self.context.p_changed_ = True should be: self.context._p_changed = True


Errata type: Technical | Page number: 176 |

The indentation of the close method does not match the class as it should.


Errata type: Technical | Page number: 234 |

The line "password, del ivery, permission" should read "password, delivery, permission" instead.


Errata type: Technical | Page number: 241 |

The line ":unittestt" should probably read ":unittest" instead.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Grok 1.0 Web Development +    VirtualBox 3.1: Beginner's Guide =
50% Off
the second eBook
Price for both: $37.50

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Basic concepts of the Zope Component Architecture
  • Use Zope Page Templates to produce HTML pages
  • Design efficient applications using models and views
  • Use Grok's automatic form generation mechanisms
  • Add selectable themes or skins to your applications
  • Index content from the models you defined and learn how to search this content by querying the catalog, including full text search
  • Understand how the Zope Object Database works and how simple and useful it is
  • Easily connect to other relational databases using SQLAlchemy
  • Create extensions to your applications
  • Understand the various options to deploy your Grok application, and use buildout—a Python-based build system for deploying applications—to create a repeatable deployment

In Detail

Python is a very popular language for web application development. It's easy to learn and powerful enough to program any kind of system. There are many options for Python web development frameworks, from lightweight packages to everything-and-the-kitchen sink solutions. However, Grok offers a solid foundation for developing powerful, extensible, and secure web applications without too much complexity. This is because it is based on a very advanced object-oriented web framework: Zope 3. Grok enables web developers to tap into the power of Zope 3, thus giving a range of useful features for our applications with very little code.

This book offers Python developers a comprehensive understanding of Grok and a look at its main features by way of developing and evolving a sample application from concept to deployment. You will learn how to use Grok to create web applications and how Grok offers you an agile and enjoyable development experience.

This book will introduce you to the Grok web development framework and show you how to create an application from start to finish. You will learn how to create an application using mostly page templates and then add features to it while reworking the code as it grows. You will learn how to use models to describe your application's domain and how to connect those models to views for presenting information to your users. You will also learn how to automatically generate forms from the models and how to store the data and make it searchable. Due to the public nature of the Web, security is an important part of any web application and you will learn how Grok's integrated security can be used to protect your application and grant access to specific users and roles when needed. Grok offers a powerful object database for storage, but can also interact nicely with any database directly or using an object-relational mapper. You will learn how to do both and when it's advisable to use each. You will also learn how to extend a third-party Grok application, how to debug it, and how to deploy it. By the end of the book, you will be able to design and develop a complete web application using Grok.

A concise, practical guide for creating powerful web applications and web sites with ease


The book takes a practical approach and dives into code right from the start. After learning how to install Grok, we create a simple application. We work on this application throughout the book, until its deployment in the last chapter.

In each chapter, some new features of Grok will be introduced and explained, then the application will be extended to use them, explaining step-by-step how each feature works.

Who this book is for

This book is intended for Python developers who want to create web applications but have little or no experience in web development. If you have used other web frameworks but are looking for one that enables you to create more complex applications without losing agility, you will also benefit from this book.

The reader is expected to have some basic Python knowledge and at least a general idea of how a web application works.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software