Personal tools
You are here: Home Documentation Tutorials Navigating To Transient Objects Tutorial

Navigating To Transient Objects Tutorial

This Tutorial applies to: Any version.
This Tutorial is intended for: Beginners

Thanks to the magic of this database, your web apps can create Python objects that are automatically saved to disk and are available every time your application runs. In particular, every grok.Model and grok.Container object you generate can be written safely to your application's Data.fs file. But sometimes you need to create objects that do not persist in the ZODB, wonderful though it is.

All content on one page (useful for printing, presentation mode etc.)

  1. Introduction Why instantiate objects from external data sources?
  2. Choosing a method In this tutorial, we introduce four methods for creating an object which you need to present on the web:
  3. Our Topic: The Natural Numbers To make this tutorial simple, we will build a small web site that lets the user visit what some people call the natural numbers: the integers beginning with 1 and continuing with 2, 3, 4, and so forth. We will define a Natural class which knows a few simple things about each number - like which number comes before it, which comes after it, and what its prime factors are.
  4. The Natural class implementation Now we merely have to provide an implementation for our Natural class.
  5. Having Your View Directly Instantiate An Object We now reach the first of our four techniques!
  6. Creating Objects Based on Form Input What if we wanted the user to be able to designate which Natural object was instantiated for display on this web page?
  7. Custom Traversers But what about situations where you want each of your transient objects to have its own URL on your site?
  8. Providing Links To Other Objects What if the object you are wrapping can return other objects to which the user might want to navigate?
  9. Writing Your Own Container The above approach, using Traversers, gives Grok just enough information to let users visit your objects, and for you to assign URLs to them.
 

Some of the explanation are not clear

Posted by geohuz at Feb 03, 2009 07:42 PM
In example of Customer Traversers, I found the following points are not clear:

1. The use of NaturalDir. It looks like a place holder object existing for NaturalTraverser to grok.context to it. because the url is sth like /app/natural/xxx, so the slash is like a folder in the system path, we need to have a context object to "contain" the sub objects.
2. The grok.name('index.html'), is it because the grok.context(Natural) is not a model/container then we need to name it explicitly?