[Zope3-dev] PythonScript in Zope3?

Steve Alexander steve@cat-box.net
Thu, 20 Feb 2003 10:11:37 +0200


Barry Pederson wrote:
> Steve Alexander wrote:
> 
>>
>> Add a folder called 'foo'. Inside the folder, add a python script 
>> called 'index.html'.
> 
> Zope3 doesn't offer python script as a choice of things you can add to a 
> content folder - that's what got me started on this whole thing in the 
> first place, finding out what the new equivalent is.

I expect Zope 3 will offer a python script as you describe.
No-one has written the proposal or the code yet.


>>>  * Can the sourcecode be as simple as: "print 'hello world'", or does
>>>    there need to be a function defined.
>>
>> Yes (but I don't know why you'd want to print anything like this).
> 
> Geez, a "hello world" sample is supposed to be trivial, to get you over 
> whatever initial hurdles there are to using a new system.  It's hard to 
> contemplate doing more worthwhile things, if you can't do simple stuff 
> first.

What I mean is, why would you want to have a 'print "hello world"' 
statement in a persistent module?

Persistent modules aren't scripts. They aren't meant to be run. In Zope, 
you don't expect to see the effects of what you have done appear on 
standard-output.

Printing 'hello world' in a print statement in a module is not an 
appropriate 'hello world' program for a persistent module.

An appropriate and minimal 'hello world' for a persistent module would 
be to define a variable in your module. So, create the mystuff.mymodule 
module, and in it write:

   message = "hello world"

Then, in a page template, you can say

  <tal:magic invocation to import module mystuff.mymodule />
  <p tal:contents="python: mystuff.mymodule.message" />

(I don't know the syntax for importing a module in TAL, as I've never 
needed to use it.)


>> If you define a persistent module, and the module name is 
>> mystuff.mymod, then you can call a function called 'myfunc' that is 
>> inside mystuff.mymod by writing this in a page template:
>>
>>   <div tal:define="result mystuff/mymod/myfunc" />
>>
>> or perhaps this:
>>
>>   <div tal:define="result python:mystuff.mymod.myfunc()" />
> 
> 
> Nope, doesn't seem to work, get a NameError: name 'mystuff' is not defined.

You'll need to get hold of the module, as described here:

http://www.zope.org/Wikis/DevSite/Projects/ZPT/ModuleAccessInTALES

So,

   <div tal:define="mymod nocall modules/mystuff/mymod">
     <p tal:contents="mymod/myfunc" />
   </div>


> Has any of this been actually tried? or is it more of a hypothetical 
> "this is how I imagine it probably works?"  or are there more steps?

I haven't tried much of this. What I describe above should work.
If I get time, I'll try it out later.
If you try it out and tell me where you get stuck, I'll try to help you.


> That's mainly what I'm asking to find out..what are the 17..no 18..18 
> easy steps to getting a 'hello world' example running from whatever 
> replaces python scripts :)

Zope 3 python scripts replace Zope 2 python scripts. Just, no-one has 
done the work to write Zope 3 python scripts.


> (or is the whole thing just not functional yet?)

Persistent modules, which live in 'service space', should work pretty well.
Python scripts, which live in 'content space', haven't been started yet.

Do you have CVS access? Perhaps you'd like to write a Python Scripts for 
Zope 3 proposal and work on the implementation?


>> You can set up a local views service, configure a view for IFolder, 
>> and provide a template and possibly a class for that (if you want).
>>
>> You can redefine the default view of IFolder to be your new view.
>>
>> This is appropriate if you want to change the default view of all 
>> folders in your site.
>> This is not appropriate if you want to put an index.html page in a 
>> single particular folder.
> 
> 
> Yeah, I'd love to see that sort of thing working, changing the default 
> view of something, but again it's not obvious what needs to go into the 
> "configure a view" form.  I've tried various things, but mostly get:
> 
>   AttributeError: GlobalViewService instance has no attribute
>    'queryConfigurationsFor'

You need to create a local views service component, and configure it to 
be the views service.

Add a views service component in your default package. In the 
configuration of your default package, add a 'service' configuration for 
the views service. Select the component you just added. Make the 
configuration 'active'.


> The big frustration with learning Zope3 right now is constantly reading 
> that you "can" do something, but specific detailed reproducible examples 
> of "how" to do something aren't easily come by.

I can't argue with that.

You are already improving the situation by trying these things, and 
asking these questions.

You can improve it more if you have time to write how-to documentation 
based on your experiences.

--
Steve Alexander