Commit 1d45d7a1 authored by Jim Fulton's avatar Jim Fulton

new interface and now can use bound methods

parent 8a2d343a
...@@ -16,10 +16,8 @@ modules={} ...@@ -16,10 +16,8 @@ modules={}
addForm=HTMLFile('methodAdd', globals()) addForm=HTMLFile('methodAdd', globals())
def add(self, id, title, external_name, REQUEST=None): def add(self, id, title, module, function, REQUEST=None):
"""Add an external method to a folder""" """Add an external method to a folder"""
names=split(external_name,'.')
module, function = join(names[:-1],'.'), names[-1]
i=ExternalMethod(id,title,module,function) i=ExternalMethod(id,title,module,function)
self._setObject(id,i) self._setObject(id,i)
return self.manage_main(self,REQUEST) return self.manage_main(self,REQUEST)
...@@ -40,22 +38,16 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, ...@@ -40,22 +38,16 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent,
{'label':'Access Control', 'action':'manage_access'}, {'label':'Access Control', 'action':'manage_access'},
) )
def __init__(self, id='', title='', module='', function=''): def __init__(self, id, title, module, function):
if id:
self.id=id self.id=id
self.title=title self.manage_edit(title, module, function)
self._module=module
self._function=function
self.getFunction()
self._p_atime=1
manage_main=HTMLFile('methodEdit', globals()) manage_main=HTMLFile('methodEdit', globals())
def manage_edit(self, title, REQUEST=None): def manage_edit(self, title, module, function, REQUEST=None):
"Change the external method" "Change the external method"
self.title=title self.title=title
names=split(external_name,'.') if module[-3:]=='.py': module=module[:-3]
module, function = join(names[:-1],'.'), names[-1] elif module[-4:]=='.py': module=module[:-4]
self._module=module self._module=module
self._function=function self._function=function
try: del modules[module] try: del modules[module]
...@@ -64,11 +56,9 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, ...@@ -64,11 +56,9 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent,
if REQUEST: return MessageDialog( if REQUEST: return MessageDialog(
title ='Changed %s' % self.id, title ='Changed %s' % self.id,
message='%s has been updated' % self.id, message='%s has been updated' % self.id,
action =REQUEST['URL2']+'/manage_main', action =REQUEST['URL1']+'/manage_main',
target ='manage_main') target ='manage_main')
def external_name(self): return "%s.%s" % (self._module, self._function)
def getFunction(self): def getFunction(self):
module=self._module module=self._module
...@@ -83,10 +73,13 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, ...@@ -83,10 +73,13 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent,
modules[module]=m modules[module]=m
f=m[self._function] f=m[self._function]
if self.func_defaults != f.func_defaults: if hasattr(f,'im_func'): ff=f.im_func
self.func_defaults = f.func_defaults else: ff=f
if self.func_defaults != ff.func_defaults:
self.func_defaults = ff.func_defaults
func_code=FuncCode(f) func_code=FuncCode(ff,f is not ff)
if func_code != self.func_code: self.func_code=func_code if func_code != self.func_code: self.func_code=func_code
self._v_f=f self._v_f=f
...@@ -99,13 +92,14 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, ...@@ -99,13 +92,14 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent,
return apply(f,args) return apply(f,args)
def function(self): return self._function
def module(self): return self._module
class FuncCode: class FuncCode:
def __init__(self, f=None): def __init__(self, f, im=0):
if f is not None: self.co_varnames=f.func_code.co_varnames[im:]
self.co_varnames=f.func_code.co_varnames self.co_argcount=f.func_code.co_argcount-im
self.co_argcount=f.func_code.co_argcount
def __cmp__(self,other): def __cmp__(self,other):
return cmp((self.co_argcount, self.co_varnames), return cmp((self.co_argcount, self.co_varnames),
......
...@@ -16,12 +16,10 @@ ...@@ -16,12 +16,10 @@
<TD ALIGN="LEFT" VALIGN="TOP"><B>Title</B></TD> <TD ALIGN="LEFT" VALIGN="TOP"><B>Title</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP"><INPUT TYPE="TEXT" NAME="title" SIZE="50"></TD> <TD ALIGN="LEFT" VALIGN="TOP"><INPUT TYPE="TEXT" NAME="title" SIZE="50"></TD>
</TR> </TR>
<TR> <tr> <th>Function name</th>
<TD ALIGN="LEFT" VALIGN="TOP"><B>External name</B></TD> <td><input name="function" size="30"></td></tr>
<TD ALIGN="LEFT" VALIGN="TOP"> <tr> <th>Python module file</th>
<INPUT TYPE="TEXT" NAME="external_name" SIZE="50"> <td><input name="module" size="30"></td></tr>
</TD>
</TR>
<TR> <TR>
<TD></TD> <TD></TD>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Add"></TD> <TD><BR><INPUT TYPE="SUBMIT" VALUE="Add"></TD>
......
...@@ -19,13 +19,13 @@ ...@@ -19,13 +19,13 @@
<INPUT TYPE="TEXT" NAME="title" SIZE="50" VALUE="<!--#var title-->"> <INPUT TYPE="TEXT" NAME="title" SIZE="50" VALUE="<!--#var title-->">
</TD> </TD>
</TR> </TR>
<tr> <th>Function name</th>
<td><input name="function" size="30"
value="<!--#var function-->"></td></tr>
<tr> <th>Python module file (without suffix)</th>
<td><input name="module" size="30"
value="<!--#var module-->"></td></tr>
<TR> <TR>
<TD ALIGN="LEFT" VALIGN="TOP"><B>External name</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="TEXT" NAME="external_name" SIZE="50"
VALUE="<!--#var external_name-->">
</TD>
</TR>
<TR> <TR>
<TD></TD> <TD></TD>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Edit"></TD> <TD><BR><INPUT TYPE="SUBMIT" VALUE="Edit"></TD>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment