[Zope-dev] Need help with Products

Ross Boylan RossBoylan@stanfordalumni.org
Sat, 06 Nov 1999 23:21:36 -0800


I am trying to create a User subclass which will hold additional
information about a user.  Could someone help me get oriented?

I've been using 3 primary sources of information: the existing poll product
(as an example), Amos Latteier's recently released "Extending Zope in
Python" slides, and Zen's "How-To: The (old) Product AP Tutorial."  The
latter notes it is out of date.  I notice, for example, that the recent
info has no reference to methods = ... to get the product creation methods
out to the folders.

Users have the additional complexity, I think, that there are two items to
be managed: the folder which holds the users (the thing which appears as
acl_list in the GUI?) and the users themselves.  My only interest in a new
folder is to assure that the right kind of user object gets created.  My
intention is that users will create their own user objects off a simple
screen asking for the basic info.

One specific problem has been that I kept getting a broken product because
UserFolder was an unrecognized symbol.  The tracebacks displayed on the
product information seemed to show the error being thrown at
class OrgUserFolder(UserFolder):
in OrgUser.py, which in turn was being called from __init__.py's import
statement.  Yet my various attempts to trap the error failed (in fact, at
least some times the code seemed to run OK when it was in the debugger).
Mysteriously, when I took the context.RegisterClass out of the __init__
file, the product reported as OK.  Note those statements occur after the
apparent point the error was thrown.

While tracing I also noticed that class definitions seemed to invoke an
__init__ method in the App hierarchy (I don't recall the specifics) at the
point they were scanned.  Can anyone tell me how such a hook gets set up in
general, and what it is doing in this case?

Another specific question is whether spaces are legal for meta type names.

I'm running on NT, and had Python 1.5.2 on my system before I installed Zope.

Here's the current code.  I've fiddled with lots of variants.
------------------------__init__.py-----------------------------------------
-------------
__doc__='''Sample PSA Organizational User
Adopted from Poll

The job of this module is to provide any run-time initialization
needed and to define meta data. '''
__version__='$Revision: 0.1 $'[11:-2]

from ImageFile import ImageFile

import OrgUser

#  meta-data:

# Names of objects added by this product:
meta_types=(
    {'name': 'PSA User' ,               # The name of the object type
     'action': 'manage_addUser', # The method to add one.     
     },
    )

# Attributes (usually "methods") to be added to folders to support
# creating objects:
methods= {
    'manage_addUserForm' :  OrgUser.addUserForm,
    'manage_addUser':  OrgUser.addUser  #I need to define this method
    }

# the following gave me an error on UserFolder being unrecognized
#def initialize(context):
#    context.registerClass(OrgUser)
 
----------------------OrgUser.py--------------------------------------------
---
from AccessControl.User import *

addUserForm = HTMLFile('addUser', globals())

class OrgUser(User):
	"""Add additional information on the user"""
	meta_type ='PSA User'
	id	= 'Organizational_User'
	title	= 'Organizational User'


	def __init__(self,name,password,roles,domains):
		User.__init__(self, name, password, roles, domains)
		self.email = "Your email here"


class OrgUserFolder(UserFolder):  ### this seems to be where I get the
error that UserFolder is unrecognized
    """Base class for UserFolder-like objects"""
    meta_type='PSA User Folder'
    id       ='PSA_users'
    title    ='Organizational User Folder'

    def _doAddUser(self, name, password, roles, domains):
       	"""Create a new user"""
        self.data[name]=OrgUser(name,password,roles,domains)


Globals.default__class_init__(OrgUserFolder)


def manage_addUserFolder(self,dtself=None,REQUEST=None,**ignored):
    """ """
    f=OrgUserFolder()
    self=self.this()
    try:    self._setObject('acl_users', f)
    except: return MessageDialog(
                   title  ='Item Exists',
                   message='This object already contains a User Folder',
                   action ='%s/manage_main' % REQUEST['URL1'])
    self.__allow_groups__=f
    
    if REQUEST: return self.manage_main(self,REQUEST,update_menu=1)