Commit 8707f471 authored by Jim Fulton's avatar Jim Fulton

first working version

parent 6651320c
...@@ -6,34 +6,62 @@ domain-specific customization of web environments. ...@@ -6,34 +6,62 @@ domain-specific customization of web environments.
""" """
from Acquisition import Implicit 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={} 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""" """Add an external method to a folder"""
names=split(external_name,'.') names=split(external_name,'.')
module, function = join(names[:-1],'.'), names[-1] module, function = join(names[:-1],'.'), names[-1]
i=ExternalMethod(id,title,roles,module,function) i=ExternalMethod(id,title,module,function)
self._setObject(name,i) i._setRoles(acl_type,acl_roles)
self._setObject(id,i)
return self.manage_main(self,REQUEST) 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 method is a web-callable function that encapsulates
an external function.""" an external function."""
meta_type='External Method' 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: if id:
self.id=id self.id=id
self.title=title self.title=title
self.roles=roles
self._module=module self._module=module
self._function=function self._function=function
self.getFunction() self.getFunction()
self._p_atime=1 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): def getFunction(self):
module=self._module module=self._module
...@@ -64,9 +92,10 @@ class ExternalMethod: ...@@ -64,9 +92,10 @@ class ExternalMethod:
class FuncCode: class FuncCode:
def __init__(self, f): def __init__(self, f=None):
self.co_varnames=f.func_code.co_varnames if f is not None:
self.co_argcount=f.func_code.co_argcount self.co_varnames=f.func_code.co_varnames
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),
......
*shared* # install ExternalMethod.py
# install __init__.py
# install addForm.dtml
# install methodAdd.dtml
# install methodEdit.dtml
# install www www/%(package)s
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<TITLE>New External Method</TITLE> <TITLE>New External Method</TITLE>
</HEAD> </HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555" ALINK="#77003B"> <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"> <FORM ACTION="manage_addExternalMethod" METHOD="POST">
<TABLE CELLSPACING="2"> <TABLE CELLSPACING="2">
...@@ -15,18 +15,18 @@ ...@@ -15,18 +15,18 @@
<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>
<!--#var smallRolesWidget-->
<TR> <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"> <TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="TEXT" NAME="ExternalName" SIZE="50"> <INPUT TYPE="TEXT" NAME="external_name" SIZE="50">
</TD> </TD>
</TR> </TR>
<TR> <TR>
<TD></TD> <TD></TD>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Add External Method"></TD> <TD><BR><INPUT TYPE="SUBMIT" VALUE="Add"></TD>
</TR> </TR>
</TABLE> </TABLE>
</FORM> </FORM>
</BODY> </BODY>
</HTML> </HTML>
<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>
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