[Zope-DB] need a suggestion regarding dtml method (and more...)

Charlie Clark charlie at egenix.com
Fri Apr 30 12:08:19 EDT 2004


Laura,

you really are having an intensive course in Zope! First of all: stick with 
ZPT and don't use DTML.

What you want to do is possible with <tal:condition="cancel"> or 
<tal:condition="edit"> but things get pretty complicated that way. It is 
usually better to pass forms to a PythonScript which can then decide what 
is the correct action to do. This allows you to concentrate on declarative 
HTML code in your PageTemplate and procedural and functional code in your 
script.

Whether a form is necessary in your case is a mute point. I think your  
current approach using links is fine - this way you either call up the edit 
form or not but I am not quite sure why you would want to do this. In HTML 
forms the input type "submit" has two values which cause the browser to do 
something: "submit" is the default and causes the browser to POST or GET 
the form to the URL declared in the "action"; "reset" causes the browser to 
clear any changes made to the form without sending anything to the server.

If you set the action of your form to a PythonScript you can ask the 
PythonScript to print out everything that was in the form.

eg.

<form action="myscript">
<input type="hidden" name="user" value="laura">

<input type="submit" name="action" value="submit">
<inout type="submit name="action" value="cancel">
</form>

with your script "myscript" looking like this:

request = context.REQUEST
print request.form
return printed

this could be extended in the future for your flow control

if request.action == "submit":
	return context.user_EditForm()
elif request.action == "cancel":
	return context.user_NoChanges()

Using PythonScripts to handle data passed from one object to another allows 
you to use the power and simplicity of Python to do this and is one of the 
strengths of Zope. But it takes some getting used to.

Have a nice weekend!

Charlie

On 2004-04-30 at 17:27:20 [+0200], Laura McCord wrote:
> 
> Hi,
> 
> I have a form that sends either an update or cancel variable to my
> user_Update_html dtml method. The problem with the code is that it does
> not do anything but show a blank grey screen if cancel was selected and
> I want it to either tell the user that the update was cancelled or go
> back to my index_html page. However, I tried revising the code including
> a <dtml-else> or another <dtml-if> to check if the value was "cancel"
> but haven't had much luck.
> 
> Any suggestions would be appreciated.
> 
> Thanks,
>  Laura
> 
> The code looks like this:
> 
> <html>
> <body bgcolor="#e7e7e7">
> <font color="#0a4f72" size="4">
> 
> <dtml-if name="update">
> <dtml-try>
>  <dtml-call name="update_user_sql">
>  The user, <strong><dtml-var name="username">,</strong>
>  was successfully update in the database.
>  <dtml-except>
>  Sorry, the user was not updated in the database.
>  </dtml-try>
> </dtml-if>
> 
> </font>
> </body>
> </html>
> 
> _______________________________________________
> Zope-DB mailing list
> Zope-DB at zope.org
> http://mail.zope.org/mailman/listinfo/zope-db

On 2004-04-30 at 17:33:19 [+0200], Laura McCord wrote:
> 
> Well I found a way to accomplish this but I did not use a submit button.
> In fact, I don't think you can pass an argument through a submit button.
> However, this is what I did:
> 
> I created an image link where the image looks similar to a button that I
> created in photoshop. Then, I created an Edit Button and Cancel button
> which you can see below. The first link contains the pass of the userid
> which is what I wanted to do.
> 
> <tr>
> <td>
> <a tal:attributes="href python: 'user_EditForm?userid=' +
> str(userid)"><img src="edit_button.gif" alt="Edit"></a>
> </td>
> <td>
> <a tal:attributes="href python: 'index_html'"><img
> src="cancel_button.gif" alt="Cancel"></a>
> </td>
> 
> Maybe this will help someone.
> 
> -Laura

-- 
Charlie Clark
eGenix.com

Professional Python Services directly from the Source
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the Zope-DB mailing list