[Zope-DB] writing a template to test if the sql worked
charlie at egenix.com
Tue May 4 11:55:25 EDT 2004
get DTML and *all* HTML scripting stuff out of your head; I think they are
the causes of lots of problems.
ZPTs are great because they encourage you to concentrate on your
presentation logic and break your procedural and data logic into external
So what you should be doing is posting your form to a PythonScript which
does the error checking and informs the result template accordingly.
Your PythonScript will look something like this
request = context.REQUEST
errors = 
error_msg = ""
except SpecificError: """you will need to change this but I'm adding to
make a point"""
error_msg += "Sorry the pc could not be added to the database"
And your ZPT might look something like this:
<body tal:define="errors request/errors | nothing">
<!-- use a stylesheet for your formatting -->
tal:content="structure request/error">Error message will be printed here</p>
<p tal:condition="not: errors">
The pc, <strong tal:content="request/pcname">PCNAME</strong> was
successfully added to the database.</p>
Notice how inflexible tal:condition is. Although this can be annoying it is
actually a "good thing". You really don't want control structures in your
presentation code. Simple binary cases: "either this or that" is as much as
Working like this will allow you to declare how specific things should be
handled - there respective success and failure messages allowing you to
reuse the code more easily. Note this is also how Formulator works so it
might be time to give that a spin.
On 2004-05-04 at 17:31:33 [+0200], Laura McCord wrote:
> If I have an edit form and I click on edit after inserting the info
> into the fields I am redirected to a dtml method that I am using to call
> the zsql method and it tests if it was successful using the <dtml-try>
> and <dtml-except> conditons. This is the code that I am using:
> <body bgcolor="#e7e7e7">
> <font color="#0a4f72" size="4">
> <dtml-if name="create">
> <dtml-call name="add_pc_sql">
> The pc, <strong><dtml-var name="pcname">,</strong>
> was successfully added to the database.
> Sorry, the pc was not added to the database.
> I have been looking in the zope book and trying to learn how I could
> change this into a page template instead of a dtml method. Is there
> anything in page templates that can do the error checking like this dtml
> method? I wasn't sure if I would be using a <tal:condition> to achieve
More information about the Zope-DB