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?


Index: lib/python/Products/ExternalMethod//ExternalMethod.py
RCS file: 
retrieving revision
diff -u -p -u -r1.1.1.1 ExternalMethod.py
--- lib/python/Products/ExternalMethod//ExternalMethod.py       2000/06/07 20:38:02
+++ 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',
-        {'label':'Try It', 'action':'',
+        {'label':'Try It', 'action':'manage_try',
@@ -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:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
<HTML lang="en">
<TITLE>Edit <dtml-var title_or_id></TITLE>
<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:

   <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>
          <dtml-if "_['sequence-item'] in ('self', 'REQUEST')">
          <i>Provided by Zope's ZPublisher internally</i>
          <input name="<dtml-var sequence-item html_quote>" size=30>

with no arguments!</h2>

<dtml-raise type="Redirect"><dtml-var URL1></dtml-raise>
<dtml-return call>





Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to