[Zope] My Way of Zope Programming

Terry Hancock hancock@anansispaceworks.com
Sat, 10 Aug 2002 00:55:45 -0700


I was a little perplexed by this assertion:

From: Jim Penny <jpenny@universal-fasteners.com>
> This is the sales pitch.  I wish Zope Corp would get over it!  The real
> benefit of ZPT, even for "non designer" sites, is that path expressions
> make it much easier to use the same form for entry and error handling,
> in a fairly readable manner.  That is, DTML design encouraged a model of
> present initial form; error check; (present error form or handle).
> 
> ZPT encourages a view of present initial form; error check; (re-present
> form or handle).

Are you sure?  It seems to me that this is not particularly
dependent on the choice of DTML vs ZPT.

What I do with DTML/Python is have 3 objects:

                Prototype          Product
myformLogic	(Python script  /  Python method)
myformForm	(DTML method    /  DTMLFile method)
myformAction	(Python script  /  Python method)

Typically, myformLogic is called from the top of myformForm (in a
dtml-let),
and computes a set of parameters, which are then displayed in the DTML
form.  The form posts to myformAction, which interprets the result. On
a reject, the original form is called, which queries myformLogic again
to recover state. The state is usually stored in hidden form elements or
in the REQUEST.  If an error condition exists, the Form object has
a dtml-if to render an appropriate error message.

By putting this analysis step into myformLogic, I avoid having overly
complex DTML in myformForm, which can then be focused on having a
good interface/layout for the user.

But then, I haven't tried ZPT, so I'm not sure I get what you
really meant. But the model above seemed very natural, and I
tend toward using it more and more. Of course, if the form
is extremely simple, you can just put the Logic in a python
expression inside the Form, and avoid having a third object.

> This make it easier to evolve the site, since you don't have to maintain
> two different forms in lock-step.
> 
> Yes, I am aware that the same could have been done in DTML.  But placing
> datasource logic in DTML tended to quickly devolve into a unreadable
> morass, so that it was easier to maintain two separate methods.

Hence the use of a Python script.

Not sure I understand the point being made.

Cheers,
Terry

-- 
------------------------------------------------------
Terry Hancock
hancock@anansispaceworks.com       
Anansi Spaceworks                 
http://www.anansispaceworks.com 
P.O. Box 60583                     
Pasadena, CA 91116-6583
------------------------------------------------------