[Zope] Re: Converting Python Methods to Python Scripts

Itai Tavor itai@optusnet.com.au
Fri, 15 Dec 2000 18:54:27 +1100


>Hi,
>
>I was wondering if anyone is planning to add automated migration of 
>Python Methods to Python Scripts (maybe with Zope 2.3 final)? Or 
>maybe there's something like this in there already that I missed?
>
>Anyway, for now I created a simple hack to do this - it's not 
>pretty, but it works. In case anyone's interested, this is how to do 
>it:
><...snip...>

Oops, bug. It didn't work in ZClasses. And while I was fixing that, I 
modified it so that if you select more than one object all will be 
converted and you'll get back to the object list.

A bug in a hack. How embarrassing. Here's the new External Method.

Still-hoping-anybody-cares-about-this, Itai


from Products.PythonScripts.PythonScript import PythonScript
from string import strip
from urllib import quote

def PythonMethod2Script(self, ids, REQUEST, RESPONSE):
     for method_id in ids:
         method_id = strip(method_id)
         method = self._getOb(method_id)

         if method.meta_type != 'Python Method':
             raise 'AppError', 'Selected object is not a Python Method'

         title = method.title
         params = method._params
         if not type(method._body) == type(''):
             body = method._body.read()
         else:
             body = method._body

         self.manage_renameObject(method_id, method_id+'X')

         id = self._setObject(method_id, PythonScript(method_id))

         script = self._getOb(method_id)
         script.ZPythonScript_setTitle(title)
         script.ZPythonScript_edit(params, body)

     if len(ids) == 1:
         return RESPONSE.redirect('%s/%s/manage' % (REQUEST['URL1'], 
quote(method_id)))
     else:
         return RESPONSE.redirect('%s/manage' % REQUEST['URL1'])
-- 
Itai Tavor                    "Je sautille, donc je suis."
C3Works    itai@c3works.com              - Kermit the Frog

"If you haven't got your health, you haven't got anything"