Accessing Documents/Methods/Properties from within External Methods.
G'day, I have a fair bit of processing going on inside of a DTML Method, so I've decided to migrate the index_html to an External Method. I would like to leave a fair bit of the document generation to DTML Documents and Methods, because, what the hey, it does that best, but I've struck some lack of knowledge in the interfaces between Zope (ZPublisher?) and Python (mostly due to cluelessness on my part, but I just don't grok "Using document templates with ZPublisher" in the DTML guide). I'll dissect my problems in piecemeal fashion: def index_html(self, REQUEST, RESPONSE): "'Ere we go, 'ere we go ..." res = [] # Just so you know what res.append() is up to. Since I don't get a chance to pass these parameters in explicitly (eg if called by "http:/foo.com/bar/"), can I assume the underlying Zope machinery will _always_ fill these in for me? doc = self.getattr('standard_html_header') # Easy enough res.append(doc(self, REQUEST)) Can of worms time. I feel uneasy with the parameters to standard_html_header, as with the examples from DTML it is usually called with (_.None, _), so I've tried (None, self) as parameters as well. Both work. Which is the correct parameter order when calling a DTML Method/Document? Are python's self (as passed in) and DTML's "_" interchangeable? Certainly, self on its own as a parameter doesn't work, and causes an authentication challange, of all things (which usually fails). Finally, getattr won't always return a callable object (say, in the case of 'title_or_id'), but I won't know that in advance. Is there an attribute I can test for that determines when to call it, and when to just str() it (and are there conditions that fall outside of these two that I've listed)? Be gentle with me. :-) Regards, Daryl Tester
Daryl Tester wrote:
doc = self.getattr('standard_html_header') # Easy enough
Oops, that's a typo - should learn to cut 'n' paste. It should read: doc = getattr(self, 'standard_html_header') # Not as easy as I thought
res.append(doc(self, REQUEST))
Can of worms time. I feel uneasy with the parameters to standard_html_header, as with the examples from DTML it is usually called with (_.None, _), so I've tried (None, self) as parameters as well. Both work.
I've found the source of my confusion at least. In the "Using External Methods" HowTo, the author is using the following form to retrieve DTML documents doc = getattr(self, docname) return doc(self, REQUEST) But I still can't find any other document that supports this view, and calling the document with (None, self) works (as I'm presuming that self is the folder containing the method, which should equate to the namespace stack - will this include REQUEST though?). Auugh! As someone else put it, "the sound of one head banging." Regards, Daryl Tester
participants (1)
-
Daryl Tester