OT Re: [Zope-DB] writing a template to test if the sql worked

Philip Kilner phil at xfr.co.uk
Thu May 6 07:20:27 EDT 2004


Hi Charlie,

Charlie Clark wrote:
>>Sure, DTML intertwines presentation and logic - but if I develop a ZPT
>>which conditionally fires python script (e.g. for form validation, or a
>>database write), is that any less "in-line scripting"?
> 
> 
> ooh, I can't see ZPT really doing either directly: surely the form's action 
> would be a script? The only case I've seen is dealing with possibly empty 
> result sets or needing to pre-process results for particular presentation 
> needs (in columns rather than rows). But even so the important thing is that 
> the ZPT *declares* everything so you stay in the same mode of speech as it 
> were. Just as your PythonScript will essentially be based around variable 
> checking and transformation and your SQL about storage and retrieval. 
> Debugging may involve switching between them a few times and ExternalEditor 
> is your friend, but the important thing is that you can focus on each bit in 
> isolation.
> 

Re. ZPT, well all my stuff is "inside" (e.g. in, or called by) 
index_html, which is a ZPT. So, calling "/therapist/add/" causes that 
ZPT to be thrown to render the request. My formulator forms are called 
by a universal "form rendering ZPT", called in turn by the top-level 
ZPT, and the sequence of forms is defined in a TinyTable - as each form 
is validated, the captured data is stashed in the session object, and 
the next form in the sequence is thrown. At the end of the sequence, 
instead of the form-rendering ZPT being called a "result" ZPT is called, 
which calls the script which commits to the RDBMS and tidies up the 
session, then displays the data in the RDBMS as confirmation - or does 
error handling stuff, or whatever.

All forms submit to ".", which equates - in my misty understanding - to 
"self" - e.g. index_html, which in turn calls the script.

So, to apply this to a new process, I only need to define the formulator 
objects, the sequence, and the results script and page - everything else 
is now automated/generic.

Re. the compartmentalisation, absolutely - each bit is intelligible.

> It's anecdotal but I recently had to do some work on a PHP site and came 
> across the usual mix of SQL embedded in PHP embedded in HTML. While the stuff 
> I was looking at was fairly cleanly typed it was still very frustrating as I 
> had to rewrite entirely for a simple change. This happens because there is 
> little or no incentive to abstract in the inline scripting world whereas the 
> ZPT / Script approach makes it imperative.
> 

Understood - in the scenario above, I initially set out merely to make 
the formulator stuff generic. However, when I'd done that I was itching 
to get the process /sequence/ out of the controlling script - which is 
otherwise also completely generic.

>>I've just made a transition in what I'm curently working on from using
>>scripts which call ZPTs (Which I found mightily confusing WRT to
>>namespace and scope issues - e.g. where a script called a ZPT which in
>>turn called a script - yuck!), to exclusively using ZPTs which call scripts.
>>
>>/I/ feel as though I've now got a much more intelligible paradigm - but
>>I'm not sure that it doesn't still qualify as in-line scripting ...
>>although of course in any one document there is no mix of logic and
>>presentation (aside from a few conditional statements).
> 
> Sounds fine to me: it is generally possible to see how things interact simply 
> from the folder structure. I normally work in a similar manner although I 
> normally pass forms to scripts to valid and process and get them to add 
> values to the request if necessary, ie. when passing error messages as I much 
> prefer this over TALES options.
> 

Yes - you originally helped us out by describing this approach. However, 
the name space and scope stuff was fatally frustrating - I feel as 
though working down from the ZPT helps me visualise it more readily, as 
if that were somehow more "tangible" if that makes any sense.

> However, Jim Penny made a very good case for having a PythonScript 
> essentially be the index_html calling ZPTs or other objects as required this 
> being a good way of preventing unpleasant or unexpected things happening. I 
> can't find it locally or online, maybe he can repost it.
> 

I'd be interested - now I've got it working "my" way, I may have picked 
up enough understanding to figure out the stuff that I couldn't suss 
before...

-- 

Regards,

PhilK

Email: phil at xfr.co.uk / Voicemail & Facsimile: 07092 070518

"The lyf so short, the craft so long to learne" - Chaucer




More information about the Zope-DB mailing list