[Zope] Problem with Simple Python Product

Luca Manini manini@flashnet.it
Fri, 5 Apr 2002 14:57:14 +0200


Hi, 

I'm writing a simple Python Product, following the lines of two
well known examples (Poll and Minimal). The Product imports fine, but
when I try do add an instance to a Folder, thus accessing 

http://localhost:9673/tests/manage_addProduct/Work/addPerson

Zope ask for authentication (I'm already in the ZMI). 

The product is very simple:
__init__.py	initialize...
IPerson.py	class IPerson (interface)
TPerson.py	class TPerson (implementation)
Person.py	class Person (Zope class) and more

The only difference I see with the Poll example is that I seperate the
pure Python class (than should be usable out of Zope) from the "Zope"
one, and the fact that I do not declare any security stuff (but
Minimal does the same). 

It is not clear to me which methods of the Person should eventually
get security declarations. I suppone only does that will be called
"through the Web", so, for example, the constructor will not need
them.

I also suppose that the security info for the Person.age method, that
is inherited from TPerson.age, could be declared in Person.py like

	security.declarePublic ('age')

Anyway I think the stuff should work even without security (or not?).

	Any hint?  
	TIA Luca.

Here goes the code:

### __init__.py ========================================

from Person import Person, addPersonForm, addPerson

def initialize(context):

    context.registerClass(
        Person,
        constructors = (addPersonForm,
                        addPerson),
        )

### IPerson.py ========================================

import Interface

class IPerson (Interface.Base):
    """ Person Interface"""

    def name(self):
        """ The name """

    def age(self):
        """ The age """

### TPerson.py ========================================

import IPerson

class TPerson:
    """ A Person - implementing IPerson"""
    
    __implements__ = IPerson.IPerson

    def __init__(self, name='Foo', age=18):
        self.name = name
        self.age  = age
    
    def name(self):
        """ The name """
        return self.name

    def age(self):
        """ The age """
        return self.age

    def __str__(self):
        return "name: %s \t age: %d" % (self.name, self.age)

### Person.py ========================================

### standard base classes
from Acquisition import Implicit
from Globals import Persistent
from AccessControl.Role import RoleManager
from OFS.SimpleItem import Item

### more Zope stuff
from Globals import DTMLFile
from AccessControl import ClassSecurityInfo

### Problem domain pure Python classes
from TPerson import TPerson

### Constructor

addPersonForm = DTMLFile ('dtml/addPerson', globals())

def addPerson (dispatcher, id, name, age):
    """ Create person and add to Destination """
    ob = Person (id, name, age)
    dispatcher.Destination()._setObject (id, ob)

### Classes
    
class Person(TPerson, Implicit, Persistent, RoleManager, Item):
    """ A Zope Person """
    
    meta_type = "Work Person"

    def __init__(self, id, name, age):
        """ Initialize a Person """
        self.id = id
        TPerson.__init__(name, age)
        
### addPerson.dtml

<!-- -*- mode:html -*- -->
  <html>
    <head>
      <title>Add Poll</title>
    </head> 
    <body> 
      <form action="addPerson"> 
	<br/> id   <input name="id">
	<br/> name <input name="name">
        <br/> age  <input name="age:int">
        <br/><input type="submit" name=" OK ">
      </form> 
    </body> 
  </html>