[Zope] zope product, object manager problem

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Jun 14 18:06:30 EDT 2004


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)








More information about the Zope mailing list