[Zope3-dev] context/@@absolute_url

Jim Fulton jim@zope.com
Sat, 14 Dec 2002 08:10:44 -0500


Guido van Rossum wrote:
> In a recent checkin, I saw this idiom:
> 
> +    <a href="configure/42"
> +       tal:attributes="href context/@@absolute_url">
> 
> Can anyone explain the context/@@absolute_url idiom? 

Yes. I'll also explain some related syntaxes and their meanings.

We sometimes, but not always, need to disambiguate name lookup during
path traversal when different namespaces overlap. The two most common
namespaces used in path traversal are the "content" and "view" namespaces.

Non-container objects have no sub-content, so the content namespace for
such objects is empty and there is no ambiguity about how to interpret
a name. A name is interpreted as a view.

Most containers allow items with names that take the same form as view names.
For these objects, we need to use an exmplicit syntax to indicate that we
want something other than content. The syntax that we settled on after much
discussion is to add a ++namespace++ prefix to names that are from an alternate
namespace.  So, to lookup a view named "absolute_url", we can use
"++view++absolute_url".

(Some containers generate item names, such as names made up from digites,
  that can't be confused with view names. For these containers, the content and
  view namespaces don't overlap and it is unnecessary to qualify view names.)

In general, we expect and hope that the "retail" users of a site will rarely, if ever
see namespace-qualified urls.  We suspect, however, that they will sometimes
see view-qualified urls.

Views are so widely used that we decided to provide a short-hand spelling for them.
The name "@@viewname" is a short-hand for "++view++viewname". This shorthand has
three advantages:

- It is shorter

- It is not english, so if we do sometimes need it in "retail" urls, it doesn't
   leak any english words.

- It provides a small visual metaphore for "view", since it looks like two eyes. :)

Originally, this syntax only applied in URLs.  We needed to be able to spell
view lookup in ZPT paths, so I invented the "views" namespace. The ZPT "views"
namespace contains views of the context objects, so:

   views/absolute_url

is equivalent to:

   context/@@absolute_url

I eventually realized thet the views namespace was inadequate, because we often need
to get at views of other objects. For example, in content listings, we might
need to get at views of items, as in "items/@@absolute_url.  That was why
I eventually made namespace lookup a feature of all path traversal.

Note that "view/name" simply traverses the current view. It is normally used to get
at view attributes or methods. It doesn't indicate view lookup.

So, to lookup a view in path, whether in ZPT, URLs, or even from Python, you
should use the "@@viewname" (or "++view++viewname") syntax. (If you need to traverse
views from Python, you need to pass a request argument to Zope.App.Traversing.traverse.)

I suggest we remove the "views" name from ZPT since it is no longer needed
and provides just one more limited "way to do it".

Jim


-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (888) 344-4332            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org