[Zope-dev] Testing external methods with arguments [PATCH]
Gisle Aas
gisle@ActiveState.com
12 Jun 2000 13:56:54 -0000
While writing on the perl external method product I back ported its
"Try It!" support to also work for python external methods that take
arguments. The change is fairly simple. Clicking the "Try it!" tab
takes you to a screen where you get a chance to fill out the arguments
for the method before you actually call it. If the function takes no
arguments, then things work the same as they do today.
I introduced a "call" alias for "__call__" in order to be able to
actaully call the method object from the DTML method. Is there a
better way?
Regards,
Gisle
Index: lib/python/Products/ExternalMethod//ExternalMethod.py
===================================================================
RCS file: /local/src/CVSROOT/Zope2/lib/python/Products/ExternalMethod/ExternalMethod.py,v
retrieving revision 1.1.1.1
diff -u -p -u -r1.1.1.1 ExternalMethod.py
--- lib/python/Products/ExternalMethod//ExternalMethod.py 2000/06/07 20:38:02 1.1.1.1
+++ lib/python/Products/ExternalMethod//ExternalMethod.py 2000/06/12 13:41:22
@@ -160,7 +160,7 @@ class ExternalMethod(OFS.SimpleItem.Item
(
{'label':'Properties', 'action':'manage_main',
'help':('ExternalMethod','External-Method_Properties.dtml')},
- {'label':'Try It', 'action':'',
+ {'label':'Try It', 'action':'manage_try',
'help':('ExternalMethod','External-Method_Try-It.dtml')},
)
+OFS.SimpleItem.Item.manage_options
@@ -205,6 +205,8 @@ class ExternalMethod(OFS.SimpleItem.Item
action =REQUEST['URL1']+'/manage_main',
target ='manage_main')
+ manage_try=HTMLFile('methodTry', globals())
+
def getFunction(self, check=0, reload=0):
f=getObject(self._module, self._function, reload)
@@ -271,7 +273,8 @@ class ExternalMethod(OFS.SimpleItem.Item
raise TypeError, v, tb
finally: tb=None
-
+
+ call = __call__
def function(self): return self._function
def module(self): return self._module
The 'methodTry.dtml' file looks like this:
------------------------------------------------------------------>8--------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML lang="en">
<HEAD>
<TITLE>Edit <dtml-var title_or_id></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555" ALINK="#77003B">
<dtml-var manage_tabs>
<FORM ACTION="<dtml-var URL1>" METHOD="GET">
<h2>Calling <dtml-var title_or_id>
<dtml-with func_code>
<dtml-if co_argcount>
with arguments:
</h2>
<table border=0>
<dtml-in co_varnames>
<dtml-if "_['sequence-index'] < co_argcount">
<tr><td align=right><b><dtml-var sequence-item html_quote></b>:</td>
<td>
<dtml-if "_['sequence-item'] in ('self', 'REQUEST')">
<i>Provided by Zope's ZPublisher internally</i>
<dtml-else>
<input name="<dtml-var sequence-item html_quote>" size=30>
</dtml-if>
</td>
</tr>
</dtml-if>
</dtml-in>
</table>
<dtml-else>
with no arguments!</h2>
<dtml-comment>
<dtml-raise type="Redirect"><dtml-var URL1></dtml-raise>
</dtml-comment>
<dtml-return call>
</dtml-if>
</dtml-with>
<INPUT TYPE="SUBMIT" VALUE="Execute"></TD>
</FORM>
</BODY>
</HTML>
------------------------------------------------------------------>8--------