[Zope3-dev] Re: Better access to APIs in paths (was Re: needing views clues
- template/title troubles)
Evan Simpson
evan@4-am.com
Mon, 24 Feb 2003 15:19:35 -0600
Jim Fulton wrote:
> context/dc:title
>
> which looks up the title api in the dc namespace for the object given
> by the context.
[...]
> In Python code, we could do:
>
> api(context).dc.title
Why do you prefer this? I find it much easier to think in terms of
accessing the 'title' property/attribute/whatever after applying the
'dc' adapter.
> <api namespace="zope" name="title"
> for="zope.app.interfaces.annotation.IAnnotatable"
> factory="zope.app.dublincore.annotatableadapter.TitleAPI">
> title meta-data attribute
>
> The title API attribute provides access to the (unqualified)
> Dublin-Core "Title" meta-data element.
> </api>
Ack! We have to implement and declare a separate API for every single
meta-data attribute??
> Some people have suggested that namespaces are just adapters.
> I think that this would be a bad idea as it would lead to very many
> small namespaces.
Only if there are a plethora of small APIs. In the example above, I
assumed that 'dc' is an adapter from IAnnotatable to an interface
(IAnnotationAccess?) that provides access to *all* of the Dublin Core
meta-data elements.
> User's objected stenuously to including xml namespace declarations in
> their zpts. We eventually, removed the necessity for declaring namespaces
> in HTML zpts. I don't think requiring namspace declarations for API
> functions would be popular.
Part of the objection, I suspect, was that declaring TAL and METAL
namespaces was utter boilerplate. At least in HTML templates, no one
cared about the ability to choose their own prefix, and the chances of a
prefix clash were essentially nil. In XML namespace declarations are
quite common.
I imagine that allowing configurable pre-defined prefixes for undeclared
namespaces would be a good thing, especially for namespaces like the
Dublin Core that are built into Zope and widely used. Cutting down the
verbosity of the declaration would help, as well:
tal:namespaces="dc zope:DublinCore"
I'm not sure what value conflation with XML namespaces adds, given the
configurability of Zope 3. Under my interpretation of the API
functionality, it would make sense to write:
tal:adapters="dc zope.DublinCore"
...where the name 'zope' lives in the root namespace for registered
adapters.
> Also note that this new syntax will be used in TALES outside of zpt.
> For example, it would be useful to use these in simple stand-alone
> TALES expressions where namespace declarations are inconventient or
> impossible
This would be another good argument for default prefixes. Also, we
could allow expressions such as "object/zope.DublinCore:title" and
"widget/plone.FooBar:baz", i.e. the prefix can be the full name of the
adapter.
Cheers,
Evan @ 4-am