Re: [Zope-dev] pseudo database records for the "in" tag?
From: julian@zereau.net I need to know how to structure dynamic tabular data (returned from an external method) so that the "in" tag can handle it like it does the results of a SQL method and do automatic variable setting etc.
Just return a sequence of mapping objects (dictionaries) or instances. One thing to note when looping over a sequence of mapping objects with the in tag, the parameter "mapping" must be set. For example, with the external method:: def emQuickTest(self): r=[] nl={'name': 'bob', 'job' : 'slob',} r.append(nl) nl={'name': 'jill', 'job' : 'pill',} r.append(nl) return r With an external method object named emQuickTest, use the following DTML: <!--#in emQuickTest mapping--> <P><STRONG>name:</STRONG> <!--#var name--><BR> <STRONG>job:</STRONG> <!--#var job--></P> <!--#/in--> ("mapping" tells the #in tag to do a 'getitem' instead of 'getattr' to get the names. 'getitem' works with dictionary/dictionary-like objects. 'getattr' works with instances.) This will result in returned HTML like the following <P><STRONG>name:</STRONG> bob<BR> <STRONG>job:</STRONG> slob</P> <P><STRONG>name:</STRONG> jill<BR> <STRONG>job:</STRONG> pill</P> .jPS | jeffrey@digicool.com zope, through the web. www.zope.org
On 09-Mar-99 Jeffrey P Shell wrote:
From: julian@zereau.net I need to know how to structure dynamic tabular data (returned from an external method) so that the "in" tag can handle it like it does the results of a SQL method and do automatic variable setting etc.
Just return a sequence of mapping objects (dictionaries) or instances. One thing to note when looping over a sequence of mapping objects with the in tag, the parameter "mapping" must be set.
Okay, I've tried this, I still have problems. I've made an external method (called "basket") - at the moment it is jury rigged to always return the mapping [{'quantity': '5', 'pcode': 'abc'}] using the "try it" tab on the method works fine and results in the text string above being sent to the browser calling <!--#var basket--> gives an error calling <!--#in basket mapping--> gives an error --- Julian Morrison Programmer (Zereau Ltd)
participants (2)
-
Jeffrey P Shell -
julian@zereau.net