[Zope] Re: Two newbie questions + Zope patch
Evan Simpson
evan@4-am.com
Wed, 08 Sep 1999 17:58:03 -0500
Chris Fassnacht wrote:
> Wow. This is a fairly mind-blowing concept.
Isn't it, though? :-) This is part of why people talk about the "Zen of Zope".
> You're saying I can pick and
> choose the stops I make on my way to an object and thereby create a unique
> collection of contexts (with their associated methods) that can be used to
> render the final object in the URL? So if I wanted the same information,
> say Info1, to be formatted for three different audiences, Aud1, Aud2, and
> Aud3, then I could (after writing the necessarily individualized methods for
> each audience) have three links like this: Root/Aud1/Info1, Root/Aud2/Info1,
> Root/Aud3/Info1, even though the containment hierarchy didn't actually
> reflect any of these URLs in its structure?
Exactly.
> By the way, did you have any suggestions on my problem with getting a
> "multi-context" path (e.g., Root/Aud1/Info1 or Root.Aud1.Info1) out of a
> lines property and rendered using the looping construct you showed me
> earlier? I know it's something simple, but I can't find a helpful reference
> to it anywhere.
Mmf. If you *really* need to be able to specify arbitrary paths (there isn't
some small collection of locations of interest?) then something like this
should do it (I do recommend '/' as a path separator):
<dtml-call "REQUEST.set('targobj', Root)">
<dtml-in "_.string.split(path, '/')">
<dtml-call "REQUEST.set('targobj', _.getattr(targobj, _['sequence-item'])">
</dtml-in>
As I think I've mentioned before on the list, it would probably save a lot of
folks a lot of grief if _['a/b/c'] and _.getattr(obj, 'a/b/c') did this
automatically. Hang on a mo'...
Here's a patch for Zope 2.0.0's DocumentTemplate/DT_Util.py which does the
trick for getattr:
122a123,127
> if '/' in name:
> for namepart in filter(None, split(name, '/')):
> inst = careful_getattr(md, inst, namepart)
> return inst
>
The other behavior I leave as an exercise for someone who likes to hack Python
C Extensions (cDocumentTemplate).