Indirection, acquisition, asphyxiation
I'm having trouble using the value of a property to determine which object to render (Zope 2.2.1, if it makes any difference). Starting from the beginning, let's say I have two folders A and B with four DTML methods (Nilo, Alpha, Smalpha, and Bravo): / Nilo /A Alpha Smalpha /B Bravo From Alpha, I can render Nilo, Smalpha, and Bravo by using this dtml: <dtml-var Nilo> (or <dtml-var "Nilo">) <dtml-var Smalpha> (or <dtml-var "Smalpha">) <dtml-var "B.Bravo"> (not <dtml-var B.Bravo>!) OK, now I want a property of folder A, call it 'choice', to determine what should be rendered by Alpha. So I rewrite Alpha to include: either <dtml-var "_[choice]"> or <dtml-var "_.getitem(choice)"> These work nicely if I set 'choice' to 'Nilo' or 'Smalpha' but I don't see how to make either one work for Bravo! Setting 'choice' to 'B.Bravo' gives me: Error Type: KeyError Error Value: B.Bravo How do I get this to work for Bravo (and still keep it working for the other cases)? Clearly my zen needs some tending to. -- Dennis Nichols nichols@tradingconnections.com
Dennis Nichols wrote:
I'm having trouble using the value of a property to determine which object to render (Zope 2.2.1, if it makes any difference). Starting from the beginning, let's say I have two folders A and B with four DTML methods (Nilo, Alpha, Smalpha, and Bravo):
/ Nilo /A Alpha Smalpha /B Bravo
From Alpha, I can render Nilo, Smalpha, and Bravo by using this dtml:
<dtml-var Nilo> (or <dtml-var "Nilo">) <dtml-var Smalpha> (or <dtml-var "Smalpha">) <dtml-var "B.Bravo"> (not <dtml-var B.Bravo>!)
OK, now I want a property of folder A, call it 'choice', to determine what should be rendered by Alpha. So I rewrite Alpha to include:
either <dtml-var "_[choice]"> or <dtml-var "_.getitem(choice)">
These work nicely if I set 'choice' to 'Nilo' or 'Smalpha' but I don't see how to make either one work for Bravo! Setting 'choice' to 'B.Bravo' gives me:
Error Type: KeyError Error Value: B.Bravo
How do I get this to work for Bravo (and still keep it working for the other cases)? Clearly my zen needs some tending to.
You can use restrictedTraverse('slash/delimited/path') If you have a slash at the start, the traversal starts from the Zope root object. Otherwise, it is relative. You can also use a sequence to represent your path. The slash at the start is represented by an empty string at the beginning of your sequence. See the documentation on the interfaces Wiki. http://www.zope.org/Members/michel/Projects/Interfaces/Traversal Also, see lib/python/OFS/Traversable.py -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Chris Withers wrote:
Steve Alexander wrote:
You can use restrictedTraverse('slash/delimited/path')
AFAIK, that's not available in DTML...
Am I wrong?
You're wrong. unrestrictedTraverse is not available from DTML though, for fairly obvious reasons. -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Steve Alexander wrote:
You can use restrictedTraverse('slash/delimited/path')
AFAIK, that's not available in DTML...
Am I wrong?
You're wrong.
Yay! :-) I guess that takes away a lot of the need for &dtml-/folder/object; So: <dtml-var "restrictedTraverse('slash/delimited/path')" absolute_url> will work as I expect it to? cool, Chris PS: Has your patch to allow &dtl.url-/folder/object; made any progress into the Zope core yet? Whiel the aboev works, your patch is a lot less RSI-inducing... :-)
Chris Withers wrote:
PS: Has your patch to allow &dtl.url-/folder/object; made any progress into the Zope core yet?
That's part of another proposal now. I really don't like having '/' characters in SGML entities. I have this heretical view that DTML should try to conform to SGML where possible. -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
At 9/15/00 10:05 AM, Chris Withers wrote:
So:
<dtml-var "restrictedTraverse('slash/delimited/path')" absolute_url>
will work as I expect it to?
Well, I don't know what you expect :-) When I try to save such a construct with the handy-dandy Change button I get Document Template Parse Error Invalid attribute name, "absolute_url", for tag <dtml-var "restrictedTraverse(choice)" absolute_url> ... -- Dennis Nichols nichols@tradingconnections.com
+-------[ Dennis Nichols ]---------------------- | At 9/15/00 10:05 AM, Chris Withers wrote: | >So: | > | ><dtml-var "restrictedTraverse('slash/delimited/path')" absolute_url> | > | >will work as I expect it to? | | Well, I don't know what you expect :-) When I try to save such a construct | with the handy-dandy Change button I get | | Document Template Parse Error | Invalid attribute name, "absolute_url", for tag <dtml-var | "restrictedTraverse(choice)" absolute_url> ... <dtml-var "restrictedTraverse(choice).absolute_url()"> I think is what is required. -- Totally Holistic Enterprises Internet| P:+61 7 3870 0066 | Andrew Milton The Internet (Aust) Pty Ltd | F:+61 7 3870 4477 | ACN: 082 081 472 ABN: 83 082 081 472 | M:+61 416 022 411 | Carpe Daemon PO Box 837 Indooroopilly QLD 4068 |akm@theinternet.com.au|
Hi, I'm trying to create an inline interface to manage_edit. If a user is authenticated, instead of seeing the default views of each snippet of content, they get a textarea with a submit button for each snippet. I'm still new to all this, so I'm not sure how I should be going about it: a zclass with the content as a property? a product that subclasses DTMLDocument and overrides the __call__ method? I settled on creating a DTML method, "editable", which works fine if you call it from the url (code included at bottom of mail): http://mysite.com/snippet/editable Inside "editable", when I call <dtml-var __str__> the content of the parent object is returned, which is what I wanted. The plan was, whenever I had a snippet which I wanted to be editable, I would call it inside my dtml thus: <dtml-var snippet/editable> which of course doesn't work. Eventually I found I had to do... <dtml-var "snippet.editable(REQUEST)"> ...because the editable method doesn't inherit the context of snippet like it does when you call it from the URL, and I needed to authenticate the user. But now I'm finding that the <dtml-var __str__> inside the editable method is actually rendering the content of the page that the snippet is in, rather than the snippet itself. How should I call the editable method of snippet in such a way that it inherits the context of snippet rather than the context of its parent? I've tried <dtml-with snippet><dtml-var editable></dtml-with> but then editable can't access any other objects, e.g. update_content, in the folder. Perhaps I should be going about this completely differently? Thanks Seb ------------------------------ editable is a DTML method: <dtml-if "AUTHENTICATED_USER.has_role('Manager')"> <form action="update_content"> <input type="text" name="title:text" value="<dtml-var title_or_id>"> <textarea name="data:text" cols="30" rows="20"> <dtml-var __str__> </textarea> <input type="submit"> </form> <dtml-else> <dtml-var __str__> </dtml-if> update_content is an external method: def update_content(self,REQUEST): self.manage_edit(data=REQUEST.form["data"],title=REQUEST.form["title"]) return REQUEST.form["data"]
Dennis Nichols wrote:
At 9/15/00 10:05 AM, Chris Withers wrote:
So:
<dtml-var "restrictedTraverse('slash/delimited/path')" absolute_url>
will work as I expect it to?
Well, I don't know what you expect :-) When I try to save such a construct with the handy-dandy Change button I get
Document Template Parse Error Invalid attribute name, "absolute_url", for tag <dtml-var "restrictedTraverse(choice)" absolute_url> ...
Yeah. That's right. There is no attrubute absolute_url. There is, however, a method absolute_url(). This should do what you expect: <dtml-var "restrictedTraverse('slash/delimited/path').absolute_url()"> -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
participants (5)
-
Andrew Kenneth Milton -
Chris Withers -
Dennis Nichols -
seb -
Steve Alexander