Personal tools
You are here: Home Documentation Tutorials Grok Poller Tutorial Naming Content

Naming Content

In the `Adding Objects`_, we made a form that creates new polls and adds them to a container. But we overlooked a problem in the way that Grok object traversal works.
This tutorial shows how to implement a simple polling application using Grok.
Page 9 of 14.
When a user calls an URL in a Grok application, ``http://localhost:8080/poller/question`` for example, Grok will try to traverse the URL "path" item by item. So at first Grok asks from a root container if it contains an item calles "poller", if it does, then the traversal moves forward and asks if the "poller" contains "question" and so on. The traversal system can be customized, but this is the default behaviour. The problem in our is the following lines from our add form class: .. code-block:: python name = poll.question self.context[name] = poll the poll name in the container is the question input by the user, but there is no validation, in this case it's a string, and it can contain any characters a Python string can contain; which poses a problem as the same name is used to traverse the URL's. How do you traverse a poll which question is "How/do/you/do?", the traverser would split this to objects separated by the slashes. The solution is to filter the names, which is easy to do in Python string manipulation. But you shouldn't do it manually, as you would have to repeat the code everywhere that works with container names. Instead you can use a ``NameChooser``, which will convert and validate names for containers. But to use it, we must delve into adapters for a bit.


Posted by Richard Stewart at Oct 29, 2010 09:05 AM
It looks like some formatting commands got lost in the move from[…]/grok-poller-tutorial.html for the paragraph/section entitled "Naming Content." So, the python code text "name = poll.question self.context[name] = poll" does not get rendered as it did in the original version of this tutorial, and it makes for confusing reading (unless you happen to find the original version at

Just thought you should know, and thanks for the tutorial.

Richard Stewart