Problem with Simple Python Product
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>
Luca Manini wrote:
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).
<snip/>
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.
<snip/>
Anyway I think the stuff should work even without security (or not?).
i'm just abt having the same problem. fact 1: these howtos are somewhat dated and really not as good as one would wish, but a good starting point. fact 2: between releases zopes security model has changed (several times). Im unsure abt security policy (default open, close open system % default closed, open closed system). If you apply old howtos to newer zopes, thats what happens. Take a look at newer products and try to understand, how THEY did it. sorry for not giving precise help hans PS: much doc simply lacks date and/or zope version info ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299
participants (2)
-
hans -
Luca Manini