[Zope] Making products that contain multiple classes

Jeff Kowalczyk jtk@adelphia.net
Mon, 14 Jan 2002 20:29:53 -0500


I became interested in trying out the new mxm product which offers a
reusable base class for products, mxmSimpleItem. I thought I'd try to
create the Student/Teacher/Course classes, with which I could later try
out the mxmRelation product. (Objects with manageable
relationships/references are the thing I've been waiting on to really
get started with Zope)

I tried to create my three classed in one product. I finally have all
classes, but all objectmanager adds call the third classes constructor.
If I add a Course, I still get a Teacher in its place, because that's
the final definition of the manage_addForm and manage_addAction.

Are multiple classes per product something that just isn't done, isn't
done with mxm, or is easily done once I know the trick?

"__init__.py" -------(some linebreaks removed)-------
import Course
import Student
import Teacher
def initialize(context):
    "This makes the object apear in the product list"
    context.registerClass(
        Course.Course,
        constructors = Course.constructors,
        icon='images/Course.gif')
    context.registerClass(
        Student.Student,
        constructors = Student.constructors,
        icon='images/Student.gif')            
    context.registerClass(
        Teacher.Teacher,
        constructors = Teacher.constructors,
        icon='images/Teacher.gif')

Course.py -------------------------------------------
from mxm import mxmSimpleItem
class Course(mxmSimpleItem.mxmSimpleItem):
    meta_type = 'Course'
    _properties = (
        {'id':'number', 'type':'int', 'mode':'w'},
        {'id':'title', 'type':'string', 'mode':'w'},
        {'id':'summary', 'type':'text', 'mode':'w'},
        {'id':'building', 'type':'string', 'mode':'w'},)
def manage_addAction(self, id=None, REQUEST=None):
    "Add instance to parent ObjectManager"
    mxmSimpleItem.addClass(self, id, Course, REQUEST)
constructors = (mxmSimpleItem.manage_addForm, manage_addAction)

Student.py and Teacher.py are essentially identical, save for the
_properties. Can I do anything to the constructors to allow this
multi-class/single product package to work?