zope product, object manager problem
I have a zope interface Person with a PersonImplementation that inherits from OFS.ObjectManager. When I try to add some product (eg a Folder) instance to an instance of a Person, everything appears to work, but nothing shows up in the listing of the person. Eg if I go to http://my.server:8080/sandbox/jdh/manage_main where jdh is a Person instance, I see There are currently no items in jdh I am posting my code below in hopes someone can point out my mistake. I am trying to follow the code example from the ZDG. Thanks, John Hunter (Zope 2.5.1b1 (source release, python 2.1, linux2), python 2.1.3, linux2) from Person import Person import Products from AccessControl import ClassSecurityInfo from Globals import DTMLFile, InitializeClass from OFS.SimpleItem import SimpleItem from OFS.PropertyManager import PropertyManager from OFS.ObjectManager import ObjectManager class PersonImplementation(SimpleItem, PropertyManager, ObjectManager): """ Person product class, implements Person interface. """ __implements__=Person meta_type='Person' security=ClassSecurityInfo() _properties=({'id':'first', 'type': 'string', 'mode': 'w'}, {'id':'last', 'type': 'string', 'mode': 'w'}, ) #_allowed_meta_types = ('Address', ) manage_options = ( ObjectManager.manage_options + PropertyManager.manage_options + SimpleItem.manage_options + ( { 'label' : 'View', 'action' : 'index_html', }, ) ) security.declarePublic('index_html') #security.declareProtected('View management screens', 'index_html') index_html=DTMLFile('www/person/index_html', globals()) def __init__(self, id, first, last): self.id=id self.first = first self.last = last security.declarePublic('getFullName') def getFullName(self): "Return full name" return '%s %s' % (self.first, self.last) def getAge(self): "Return age" return 12 def all_meta_types(self): """ Returns what meta_types can be added to the objectmanager """ if hasattr(self, '_allowed_meta_types'): result = [] for metaType in Products.meta_types: if metaType['name'] in self._allowed_meta_types: result.append(metaType) return result else: return Products.meta_types def addPersonForm(dispatcher): """ Returns an HTML form. """ return """<html> <head><title>Add Person</title></head> <body> <form action="addPersonFunction"> id <input type="type" name="id"><br> first <input type="type" name="first"><br> last <input type="type" name="last"><br> <input type="submit" value="Add"> </form> </body> </html>""" def addPersonFunction(dispatcher, id, first, last, REQUEST=None): """ Create a new person and add it to myself """ n=PersonImplementation(id, first, last) dispatcher.Destination()._setObject(id, n) if REQUEST is not None: return dispatcher.manage_main(dispatcher, REQUEST) InitializeClass(PersonImplementation)
Hey John, Shouldn't your class also inherit from Globals.Persistent and Aquisition.Implicit? BTW the Zope Bible has does good job describing the zope product developement. David ----- Original Message ----- From: "John Hunter" <jdhunter@ace.bsd.uchicago.edu> To: <zope@zope.org> Sent: Monday, June 14, 2004 3:06 PM Subject: [Zope] zope product, object manager problem
I have a zope interface Person with a PersonImplementation that inherits from OFS.ObjectManager. When I try to add some product (eg a Folder) instance to an instance of a Person, everything appears to work, but nothing shows up in the listing of the person.
Eg if I go to
http://my.server:8080/sandbox/jdh/manage_main
where jdh is a Person instance, I see
There are currently no items in jdh
I am posting my code below in hopes someone can point out my mistake. I am trying to follow the code example from the ZDG.
Thanks, John Hunter
(Zope 2.5.1b1 (source release, python 2.1, linux2), python 2.1.3, linux2)
from Person import Person import Products from AccessControl import ClassSecurityInfo from Globals import DTMLFile, InitializeClass from OFS.SimpleItem import SimpleItem from OFS.PropertyManager import PropertyManager from OFS.ObjectManager import ObjectManager
class PersonImplementation(SimpleItem, PropertyManager, ObjectManager): """ Person product class, implements Person interface. """
__implements__=Person
meta_type='Person' security=ClassSecurityInfo()
_properties=({'id':'first', 'type': 'string', 'mode': 'w'}, {'id':'last', 'type': 'string', 'mode': 'w'}, )
#_allowed_meta_types = ('Address', )
manage_options = ( ObjectManager.manage_options + PropertyManager.manage_options + SimpleItem.manage_options + ( { 'label' : 'View', 'action' : 'index_html', }, ) )
security.declarePublic('index_html') #security.declareProtected('View management screens', 'index_html') index_html=DTMLFile('www/person/index_html', globals())
def __init__(self, id, first, last): self.id=id self.first = first self.last = last
security.declarePublic('getFullName') def getFullName(self): "Return full name" return '%s %s' % (self.first, self.last)
def getAge(self): "Return age" return 12
def all_meta_types(self): """ Returns what meta_types can be added to the objectmanager """ if hasattr(self, '_allowed_meta_types'): result = [] for metaType in Products.meta_types: if metaType['name'] in self._allowed_meta_types: result.append(metaType) return result else: return Products.meta_types
def addPersonForm(dispatcher): """ Returns an HTML form. """ return """<html> <head><title>Add Person</title></head> <body> <form action="addPersonFunction"> id <input type="type" name="id"><br> first <input type="type" name="first"><br> last <input type="type" name="last"><br> <input type="submit" value="Add"> </form> </body> </html>"""
def addPersonFunction(dispatcher, id, first, last, REQUEST=None): """ Create a new person and add it to myself """ n=PersonImplementation(id, first, last) dispatcher.Destination()._setObject(id, n)
if REQUEST is not None: return dispatcher.manage_main(dispatcher, REQUEST)
InitializeClass(PersonImplementation)
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
"David" == David Hassalevris <bluepaul@earthlink.net> writes:
David> Hey John, Shouldn't your class also inherit from David> Globals.Persistent and Aquisition.Implicit? SimpleItem, from which my PersonImplemetation derives, already derives from these two classes, but you got my hopes up for a minute :-). Perhaps there is some initialization call for classes that derive from Globals.Persistent to make it do it's thing? David> BTW the Zope Bible has does good job describing the zope David> product developement. David Thanks, I'll take a look. JDH
Hey John, SimpleItem imports the mods but the Item Class does not inherit from them. If I am wrong on this *sorry* lol. I referred to the Zope Bible and its example product class does this: -----------------------------------------------------------
From OFS.SimpleItem import Item From Globals import Persistent From Acuisition import Implict
class helloClass(Item,Persistent, Implicit) -------------------------------------------------------------- So for a reason Item *and* Peristent and Implict are imported and subclassed... So unless something changed since zope version 2.5.0 its worth a relook. David ----- Original Message ----- From: "John Hunter" <jdhunter@ace.bsd.uchicago.edu> To: "David Hassalevris" <bluepaul@earthlink.net> Cc: <zope@zope.org> Sent: Monday, June 14, 2004 6:20 PM Subject: Re: [Zope] zope product, object manager problem
"David" == David Hassalevris <bluepaul@earthlink.net> writes:
David> Hey John, Shouldn't your class also inherit from David> Globals.Persistent and Aquisition.Implicit?
SimpleItem, from which my PersonImplemetation derives, already derives from these two classes, but you got my hopes up for a minute :-). Perhaps there is some initialization call for classes that derive from Globals.Persistent to make it do it's thing?
David> BTW the Zope Bible has does good job describing the zope David> product developement. David
Thanks, I'll take a look.
JDH
"David" == David Hassalevris <bluepaul@earthlink.net> writes:
David> Hey John, SimpleItem imports the mods but the Item Class David> does not inherit from them. If I am wrong on this *sorry* David> lol. David> I referred to the Zope Bible and its example product class David> does this: David> ----------------------------------------------------------- >> From OFS.SimpleItem import Item From Globals import Persistent >> From Acuisition import Implict David> class helloClass(Item,Persistent, Implicit)
From the src code of SimpleItem.py
class SimpleItem(Item, Globals.Persistent, Acquisition.Implicit, AccessControl.Role.RoleManager, ): I think what you are saying is true for Item, but I am deriving from SimpleItem. If you have any more suggestions, I all ears.... JDH
* John Hunter <jdhunter@ace.bsd.uchicago.edu> [2004-06-15 00:31]:
I have a zope interface Person with a PersonImplementation that inherits from OFS.ObjectManager. When I try to add some product (eg a Folder) instance to an instance of a Person, everything appears to work, but nothing shows up in the listing of the person.
The order of your base classes is messing this up. SimpleItem's objectValues returns an empty tuple to prevent SimpleItems from acquiring their parents' objectValues. changing your class definition to: class PersonImplementation(ObjectManager, PropertyManager, SimpleItem): should fix it. Why don't you just subclass Folder instead? -- Roché Compaan Upfront Systems http://www.upfrontsystems.co.za
"Roch�" == Roch� Compaan <roche@upfrontsystems.co.za> writes:
Roch�> The order of your base classes is messing this Roch�> up. SimpleItem's objectValues returns an empty tuple to Roch�> prevent SimpleItems from acquiring their parents' Roch�> objectValues. Roch�> changing your class definition to: class Roch�> PersonImplementation(ObjectManager, PropertyManager, Roch�> SimpleItem): should fix it. Yep, that's it. Thank you very much! It would have taken me quite a while to find that one on my own. Roch�> Why don't you just subclass Folder instead? The main thing I want to be able to do is limit the allowed meta types, eg _allowed_meta_types = ('Address', ) can I do this subclassing folder? Thanks again, John Hunter
participants (4)
-
David Hassalevris -
Jens Vagelpohl -
John Hunter -
Roché Compaan