[Zope] script or external method ?
J Cameron Cooper
zope-l at jcameroncooper.com
Mon Apr 4 05:25:17 EDT 2005
debugworld-linux at yahoo.it wrote:
> Hi all,
> i'm a new user of Zope; i'm studing it since two weeks
> and i think it's very
> interesting, 'cause has the same power of j2ee
> application server but it is
> much more easy to use!
> While i was developing my first Zope application i
> fell into this trouble: i
> would like to write a script that create a folder, put
> some file in it, and
> set some properties.
> The code i've writed imports date object from datetime
> package: this makes it
> doesn't work like a script (python), so i adapt code
> as an external method; but
> when i run the method Zope says that he can't find
> symbol 'container'... (mumble)
>
> Well, 2 are the questions:
> First, what i've to do to get service variable like
> like container, context, request, etc.. ?
> Which are differences between script and external
> method coding? i remember that the zope book
> indicates only imports.
Python scripts (the TTW kind) have security restrictions and have
special procedures for setting the name and the parameters of a method.
(Via the TTW forms: notice that you don't write def methodname() et al.)
There are also some special names bound, like context and so forth.
External methods are regular Python methods in a Python module which are
made available to be used live in Zope. Just as in any Python method,
you can get to the context in which it was called through the 'self'
parameter, which you will define as the first param. This is the same as
'context' in a Python script. So you can say::
def getThisId(self):
return self.getId()
You can get the request like 'self.REQUEST'. The container can be found
with self.aq_inner.aq_parent or something like that.
Alternately, you can allow modules in Python scripts. See
zope/lib/python/Products/PythonScripts/README or
http://svn.zope.org/Zope/trunk/lib/python/Products/PythonScripts/README.txt?rev=24563&view=auto
--jcc
More information about the Zope
mailing list