ZopeMag's mascot the ZOPE fish


Article Finder
People
Issue 1 - Revision 5  /   June 14, 2002 


 
  ZopeMag Links:
Home Page
About the Fish
Issue 09
Issue 08
Issue 07
Issue 06
Issue 05
Issue 04
Issue 03
Issue 02
Issue 01
Latest Issue

 
 
Downloads
     
  Letter from the Editor:
   Welcome

Interviews:
In our first issue we interview the father of the Wiki and the inventor of Extreme Programming.

 Ward Cunningham

Tutorials:
Throughout the quarter we cover topics of interest to Zope developers, designers, and users.

  MetaFlow
  Databases and ZPTs
  Custom User Folders
  Zope and CSS
  Intranets

Product Review:
Every two weeks we review a new Zope Product

  Z Shrink
  External File
  DocumentLibrary
  ZWiki


 
 
Downloads
     
  Downloads:
Products we talk about in this issues Articles and Reviews

  ZShrink
  Zope Page Templates
  LocalFS
  SimpleZPTmyAdmin
  Extended User Folder
  MetaFlow
 
     



Customized User Folders Part I
Write your own product that suits you best.
- - - - - - - - - - - -

By Kristoph Kirchner | May 22, 2002


Example: Adding an Email Property to Users

If you want to add extra properties to your users, you can use the existing user and user folder classes as a basis. That way, you do not need to concern yourself with the actual authentication mechanism and can minimize your code to a couple of methods.

For example, if you want to store email addresses with your users, create a new product that consists of two classes: a new user class (e.g., ExtendedUser) and a new user folder class (e.g., ExtUserFolder). Use the SimpleUser class and the UserFolder class respectively as base classes.

Note: In your __init__.py file, you only need to register the user folder class not the user class.

The SimpleUser class has everything you need for the new user except for a property called email and a method that returns this property. First, you need to overwrite the SimpleUser class' __init__() method. Add the new property as argument to the method and define an attribute email for the self object. Then, create a method getEmail(self) which simply returns the email attribute. The following code shows the complete user class ExtendedUser:

Listing 1: The New User Class ExtendedUser
 
class ExtendedUser(User.SimpleUser):
	""" User with additional email property """

	def __init__(self,name,password,roles,domains,email):
		""" constructor method """
		self.name   =name
		self.__     =password
		self.roles  =roles
		self.domains=domains
		self.email  =email
		
	def getEmail(self):
		""" returns the user's email """
		return self.email
 		
 

That is all you need to do in this class. Everything else is already done in the base class SimpleUser.

The new user folder class needs a bit more but not much. You need to define a meta type for this class so that you will be able to add it to a folder by selecting the meta type from the drop-down menu (line 3, Listing 2).

There are also some variables that you need to define in your class (lines 4-9, Listing 2). These variables are:

  • _mainUser (only if you want to change the look of the user overview screen)
  • _add_User
  • _editUser

If you don't declare these variables, the ones declared in the base class UserFolder will be used. This will result in them being used in the wrong context. When adding or editing a user, you will not get the forms for your user folder, i.e. the forms that contain extra fields for the email of a user, but you will get the standard forms of the Zope user folder.

Because the user folder contains the methods that manage the users, you have to overwrite all methods that concern the adding and editing of users. These methods are:

  • _addUser()
  • _changeUser()
  • _doAddUser()
  • _doChangeUser()

Copy these methods from the UserFolder class and modify them so that they will add or change the email property for the user (lines 40, 74, 78, 84, 91, Listing 2).

Listing 2: The New User Class ExtendedUser
. Click Here for the code example



.  1  2  3
Next page  |  Listing 3: Additional Code for addUser.dtml


shim
shim  ZopeMag is committed to bringing you the best in Zope Documentation. shim
shim


Home   Subscribe   FAQ   Contact   Write for us   Privacy Policy   Weekly News   PyZine   opensourcexperts.com  

Reproduction of material from any of ZopeMag's pages without prior written permission is strictly prohibited. Copyright 2003 - 2005 ZopeMag Zope/Plone hosting by Nidelven IT