return a value from python script
Hi, I have a master detail form which is sent to a python script. The detail part of the form uses the records converters. The python script works ok and the records are updated in a MySQL database. #contact ----- inserts master record ----- context.StaffInsertMethod() ----- inserts detail records ----- for x in contact: name = x['name'] job = x['job'] context.ContactInsertMethod(name=name, job=job) return 'ok' How can I respond to the 'ok' that is returned in a DTML document? Calling the script from a DTML document returns exactly the same thing as calling the script directly from the form. -- ------------ S.Morris
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of S.Morris
How can I respond to the 'ok' that is returned in a DTML document? Calling the script from a DTML document returns exactly the same thing as calling the script directly from the form.
I am not really shure what you are asking here, but are you calling your python method like <dtml-call "yourScript()"> and not like <dtml-call yourscript> ?? The first one will execute the method, the second one will return the text of the method. Just like Python does. regards Max M Max M. W. Rasmussen, Denmark. New Media Director private: maxmcorp@worldonline.dk work: maxm@normik.dk ----------------------------------------------------- Shipping software is an unnatural act
Max M writes:
I am not really shure what you are asking here, but are you calling your python method like <dtml-call "yourScript()"> and not like <dtml-call yourscript> ?? The first one will execute the method, the second one will return the text of the method. I am sure, you are not right...
None of the two returns a value: "call discards the return value". In your first variant, you explicitly call "yourScript" and have control over the parameters passed. In the second variant, DTML calls the script for you and may automatically bind "_" and pass automatically parameters from "_". This may be the case, too, for the first variant (I am not sure; in fact, I doubt it). Then, there would be no difference. Dieter
Hi, I have a form which when submitted calls a python scripts. The python scripts in turn calls a ZSQLMethod which enters data into a MySQL data. When the python script has done the data entry, either succesfully or not I would like it to point to a DTML method which will report on the action to the user. What is the best way to do this: 1. Form -> DTML Method x -> ZSQL Method -> DTML Method x How do I return a success or failure flag from the ZSQLMethod to DTML Method x? Does the ZSQL Method return anything once it has done it's operation? 2. Form -> PythonScript y -> ZSQL Method -> PythonScript y ->DTML Method x This option is neater (Python v DTML) for the kind of SQL I'm doing but I don't know how to return a success or failure flag to the final DTML method to report to the user. I don't want to send the form directly to the ZSQL because I need to perform some action on the form fields. Any advice? Thanks, Sion --
[Sion Morris]
I have a form which when submitted calls a python scripts. The python scripts in turn calls a ZSQLMethod which enters data into a MySQL data. When the python script has done the data entry, either succesfully or not I would like it to point to a DTML method which will report on the action to the user.
I suggest you don't do it like that, because this design introduces extra coupling between the components. It's better to avoid that if possible. Instead, have the python script return to its caller, then have the caller call the DTML method or just render the response on the page. The script just needs to return a zero or non-zero, which is easy to check. Cheers, Tom P
Sion Morris writes:
How do I return a success or failure flag from the ZSQLMethod to DTML Method x? Does the ZSQL Method return anything once it has done it's operation? I know of only a single way, a Z SQL Method can signal failure:
it raises an exception This exception is propagated until it hits an exception handler. There is an exception handler in ZPublisher. It will turn the exception into a 500 HTTP response (internal server error). If you do not like this failure indication, you need to catch the exception earlier. You will need the "try: ... except:..." clause in Python script or the "dtml-try" tag in DTML. See (e.g.) URL:http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html for details. Dieter
participants (5)
-
Dieter Maurer -
Max M -
S.Morris -
Sion Morris -
Thomas B. Passin