[Zope-DB] ZPT and ZSQL Method calling

Jim Penny jpenny at universal-fasteners.com
Thu Jun 24 10:56:10 EDT 2004


On Mon, 21 Jun 2004 11:53:36 +0100 (BST)
"Ian Steel" <ian at bilstone.co.uk> wrote:

> Hi,
> 
> Just started with Zope and it looks good.
> 
> I'm having a problem though and can't see the wood for the trees
> anymore.
> 
> Scenerio.
> 
> 
> I've tried this :
> 
> <div tal:define='xxx
> nocall:here/get_offered_detail(o.id=here/feature_title_id)'>
> Art: <span tal:replace="xxx/artist_name">tosh</span>
> </div>

You have several problems at once here.  
1)  if you have to parameterize, you need the python: tag.
2)  The repeat: tag is the normal way to access database variables, even
    if you expect at most one response.
3)  define: is sometimes useful with queries.  I will show how in a
    moment, but is not where you are hung up.

You want something like:

<div tal:repeat="od here/feature_item_id/get_offered_detail">
  Art: <span tal:replace="od/artist_name">tosh</span>
</div>

(this only works if the parameter of get_offered_detail is in the
request.)

Or.

<div tal:repeat='od
python:container.get_offered_detail(o.id=here/feature_title_id)'>
 Art: <span tal:replace="od/artist_name">tosh</span>
</div>

I prefer container to here, wherever possible.  Here implies an
acquisition search, container is direct, and so, should be faster.  It
is certainly much easier to debug.

Now, it is sometimes useful to define a search.  I haven't seen this
refered to much, so an example follows:

<div tal:define="odres here/feature_item_id/get_offered_detail">
  <div tal:condition="python:len(odres)==0">
    Not in database.
  </div>
  <div tal:condition="python:len(odres)>0">
    <div tal:repeat="od odres">
      ...
      <p><span tal:replace="python:len(odres)" /> rows were found.</p>
    </div>
  </div>
</div>

This shortens the code.  More importantly, it has reduced the number of
queries to the database for 2 or 4 (depending on how many rows there
are) to 1.  This can make a noticeable speed difference.

Jim Penny

> 
> but no luck.
> 
> I've tried this :
> 
> <div tal:define='xxx nocall:here/feature_item_id/get_offered_detail'>
> Art: <span tal:replace="xxx/artist_name">tosh</span>
> </div>
> but it complains that 'int doesn't have an attribute called
> get_offered_detail'.
> 
> I've tried this :
> 
> <div tal:define='xxx nocall:here/get_offered_detail/feature_title_id'>
> Art: <span tal:replace="xxx/artist_name">tosh</span>
> </div>
> I'm sure what I'm trying to attempt isn't beyond Zope, its just the
> way I'm doing it.
> 
> which doesn't work, and yet this works:
> 
> <div tal:define='xxx nocall:here/get_offered_detail/85'>
> Art: <span tal:replace="xxx/artist_name">tosh</span>
> </div>
> I'm sure what I'm trying to attempt isn't beyond Zope, its just the
> way I'm doing it.
> 
> Could someone please point me in the right direction?
> 
> Thanks,
> 
> Ian.
> 
> 
> _______________________________________________
> Zope-DB mailing list
> Zope-DB at zope.org
> http://mail.zope.org/mailman/listinfo/zope-db
> 
> 


More information about the Zope-DB mailing list