Skip to content

Commit

Permalink
first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Oct 9, 1997
1 parent 3776da4 commit 17c0412
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 16 deletions.
49 changes: 39 additions & 10 deletions ExternalMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,62 @@
"""

from Acquisition import Implicit
from Globals import Persistent, HTMLFile, MessageDialog
import OFS.SimpleItem
from string import split, join
import AccessControl.Role

brain_dir=SOFTWARE_HOME+'/Extensions'
braindir=SOFTWARE_HOME+'/Extensions'
modules={}

def add(self, id, title, roles, external_name, REQUEST=None):
addForm=HTMLFile('ExternalMethod/methodAdd')

def add(self, id, title, external_name, acl_type='A',acl_roles=[], REQUEST=None):
"""Add an external method to a folder"""
names=split(external_name,'.')
module, function = join(names[:-1],'.'), names[-1]
i=ExternalMethod(id,title,roles,module,function)
self._setObject(name,i)
i=ExternalMethod(id,title,module,function)
i._setRoles(acl_type,acl_roles)
self._setObject(id,i)
return self.manage_main(self,REQUEST)

class ExternalMethod:
class ExternalMethod(OFS.SimpleItem.Item, Persistent, AccessControl.Role.RoleManager):
"""An external method is a web-callable function that encapsulates
an external function."""

meta_type='External Method'
icon='ExternalMethod/function.gif'
func_defaults=()
func_code=None

def __init__(self, id='', title='', roles='', module='', function=''):
def __init__(self, id='', title='', module='', function=''):
if id:
self.id=id
self.title=title
self.roles=roles
self._module=module
self._function=function
self.getFunction()
self._p_atime=1

manage=HTMLFile('ExternalMethod/methodEdit')
def manage_edit(self, title, external_name, acl_type='A', acl_roles=[],
REQUEST=None):
"Change the external method"
self.title=title
names=split(external_name,'.')
module, function = join(names[:-1],'.'), names[-1]
self._module=module
self._function=function
self.getFunction()
self._setRoles(acl_type,acl_roles)
if REQUEST: return MessageDialog(
title ='Changed %s' % self.id,
message='%s has been updated' % self.id,
action =REQUEST['URL2']+'/manage_main',
target ='manage_main')

def external_name(self): return "%s.%s" % (self._module, self._function)

def getFunction(self):

module=self._module
Expand Down Expand Up @@ -64,9 +92,10 @@ def __call__(self, *args):

class FuncCode:

def __init__(self, f):
self.co_varnames=f.func_code.co_varnames
self.co_argcount=f.func_code.co_argcount
def __init__(self, f=None):
if f is not None:
self.co_varnames=f.func_code.co_varnames
self.co_argcount=f.func_code.co_argcount

def __cmp__(self,other):
return cmp((self.co_argcount, self.co_varnames),
Expand Down
7 changes: 6 additions & 1 deletion Setup
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
*shared*
# install ExternalMethod.py
# install __init__.py
# install addForm.dtml
# install methodAdd.dtml
# install methodEdit.dtml
# install www www/%(package)s
10 changes: 5 additions & 5 deletions addForm.dtml → methodAdd.dtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TITLE>New External Method</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555" ALINK="#77003B">
<FONT SIZE="+2" COLOR="#77003B">New External Method</FONT>
<h2>New External Method</h2>

<FORM ACTION="manage_addExternalMethod" METHOD="POST">
<TABLE CELLSPACING="2">
Expand All @@ -15,18 +15,18 @@
<TD ALIGN="LEFT" VALIGN="TOP"><B>Title</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP"><INPUT TYPE="TEXT" NAME="title" SIZE="50"></TD>
</TR>
<!--#var smallRolesWidget-->
<TR>
<TD ALIGN="LEFT" VALIGN="TOP"><B>External name:</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP"><B>External name</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="TEXT" NAME="ExternalName" SIZE="50">
<INPUT TYPE="TEXT" NAME="external_name" SIZE="50">
</TD>
</TR>
<TR>
<TD></TD>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Add External Method"></TD>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Add"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>

35 changes: 35 additions & 0 deletions methodEdit.dtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<HTML>
<HEAD>
<TITLE>Edit <!--#var title_or_id--></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555" ALINK="#77003B">
<h2>Edit <!--#var title_or_id--></h2>

<FORM ACTION="manage_edit" METHOD="POST">
<TABLE CELLSPACING="2">
<TR>
<TD ALIGN="LEFT" VALIGN="TOP"><B>Id</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP"><!--#var id--></TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP"><B>Title</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="TEXT" NAME="title" SIZE="50" VALUE="<!--#var title-->">
</TD>
</TR>
<!--#var smallRolesWidget-->
<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>
<TD></TD>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Edit"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>

0 comments on commit 17c0412

Please sign in to comment.