[Zope] General ZOPE Programming Question

Thomas Weiner weiner@tu-harburg.de
Sun, 05 Mar 2000 17:20:27 +0100


Michael Lausch schrieb:
> 
> I want to do the following tasks
> 
> A user enters a list of products. Such a list is equivalent to
> an order. Then i want the user to enter some things for each
> product. I don't want to implement DTML pages for each
> combination of products and i want to present one entry
> screen for each order.
> 
> I tried the following approach:
> I created a Folder named 'Products'. In this folder i
> created subfolders named after the prducts code number,
> e.g. `4007', `4008'., ....
> 
> In each of these folders i defined a DTML Method `New' which
> hholds the DTML code to create an input form fr this product. My
> plan is also to create methods named 'Display', 'Edit', .... so
> i can render the objects in different ways.

A more zopish would be: define your 'New', 'Display' and 'Edit' methods
in the Products folder and use properties in the subfolders for the
different rendering. For example:

give each subfolder a property 'Description', and a property 'Price', in
your Display method put something like:

Description: <dtml-var Description><br>
Costs: <dtml-var Price>

So, with an url http://yourhost/Products/4007/Display

Display is rendered in the context of the object '4007' and its
properties will be used.

> In anotehr page i want to do something like:
> 
> <dtml-in products>
>    <dtml-var "URL1 + '/Products/' + _['sequence-item'] + '/New'">
> </dtml-in>

This is a bit unclear. Where do you call it (note that Zope doesn't know
'pages', it only knows objects, which define what's going on) and where
does the 'products' come from? I assume you want something like this:

<dtml-in "objectValues(['Folder'])"> 
   <dtml-var absolute_url>/New <dtml-var title_or_id><br>
</dtml-in>

objectValues(['Folder']) gives a list of all (sub)folders of the current
object. Note, that if you put this into a DTML Document, the list will
be empty, because a DTML Document is an object by itself, which has no
folders associated with. You'll need in an DTML Document a <dtml-with
"PARENTS[0]">, this will include the namespace of the folder object,
where the DTML Document is called from.

For each found item <dtml-var absolute_url> displays the absolute url

> 
> but this doesn't work. Nothing is displayed. I also tries
> <dtml-var expr="...."> and <dtml-call "..."> (the last one
> was pure desperation).
> 
> So what's the correct method for implementig such a system?

Generally, this sounds like a typical ZClass task. Have a look into the
ZClass tutorial and into the example products (there is one called the
boring product on Zope.org) for more informations.

hth,
Thomas