Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: Dev

pseudo database records for the "in" tag?

 

 

Zope dev RSS feed   Index | Next | Previous | View Threaded


julian at zereau

Mar 9, 1999, 3:00 AM

Post #1 of 4 (347 views)
Permalink
pseudo database records for the "in" tag?

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.


---
Julian Morrison
Programmer (Zereau Ltd)


jeffrey at Digicool

Mar 9, 1999, 8:15 AM

Post #2 of 4 (333 views)
Permalink
Re: pseudo database records for the "in" tag? [In reply to]

> From: julian [at] zereau 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 [at] digicool
zope, through the web. www.zope.org


julian at zereau

Mar 9, 1999, 9:22 AM

Post #3 of 4 (334 views)
Permalink
Re: pseudo database records for the "in" tag? [In reply to]

On 09-Mar-99 Jeffrey P Shell wrote:
>> From: julian [at] zereau 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)


tseaver at palladion

Mar 9, 1999, 2:58 PM

Post #4 of 4 (333 views)
Permalink
Re: pseudo database records for the "in" tag? [In reply to]

>
> On 09-Mar-99 Jeffrey P Shell wrote:
> >> From: julian [at] zereau 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

try <!--#in "basket()" mapping-->
<P> <!--#var quantity--> | <!--#var pcode-->
<!--#/in-->

--
=========================================================
Tres Seaver tseaver [at] palladion 713-523-6582
Palladion Software http://www.palladion.com

Zope dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.