Adding another base class to an existing ZClass
I've spent many hours working on a ZClass (with multiple sub-zclasses, etc.), and now I've decided that I should have inherited from Folder as well as ObjectManager when I created the ZClass. Is there a way to add a base class to the base class list of an existing ZClass, or do I need to start all over? Thanks, Steve
----- Original Message ----- From: "Steve Jibson" <stevej@parlant.com> To: <zope@zope.org> Sent: Friday, January 07, 2000 6:22 PM Subject: [Zope] Adding another base class to an existing ZClass
I've spent many hours working on a ZClass (with multiple sub-zclasses, etc.), and now I've decided that I should have inherited from Folder as well as ObjectManager when I created the ZClass. Is there a way to add a base class to the base class list of an existing ZClass, or do I need to start all over?
Did anyone ever reply to this, or are you still trying to figure it out? I've seen something in the Zope how-tos or guides about the "class id" field on the "basic" tab of the ZClass, and swapping out one ZClass for another. I THINK the basic idea is that you would copy or export everything you want to keep (such as child ZClasses and methods) to a safe place, copy the ZClass's class id to a file somewhere, then delete the ZClass. Create a new one with the same id, deriving from whatever you need. Then replace the new class's id with the one you saved in the file. Finally, re-import or paste the things you needed to keep from the old class. I have not tested the above and have no idea if it would work, so I really recommend backing your database up before you try it. If you do try it, let me know how it works out. - Gregor
AFAIK, there is no approved way to add a base class to an existing ZClass. I've heard from other people at DC that it is possible, but it's a "hold on to your butts" experience. That said, I have no idea whether Gregor's method will work or not. Gregor wrote:
----- Original Message ----- From: "Steve Jibson" <stevej@parlant.com> To: <zope@zope.org> Sent: Friday, January 07, 2000 6:22 PM Subject: [Zope] Adding another base class to an existing ZClass
I've spent many hours working on a ZClass (with multiple sub-zclasses, etc.), and now I've decided that I should have inherited from Folder as well as ObjectManager when I created the ZClass. Is there a way to add a base class to the base class list of an existing ZClass, or do I need to start all over?
Did anyone ever reply to this, or are you still trying to figure it out?
I've seen something in the Zope how-tos or guides about the "class id" field on the "basic" tab of the ZClass, and swapping out one ZClass for another.
I THINK the basic idea is that you would copy or export everything you want to keep (such as child ZClasses and methods) to a safe place, copy the ZClass's class id to a file somewhere, then delete the ZClass.
Create a new one with the same id, deriving from whatever you need. Then replace the new class's id with the one you saved in the file. Finally, re-import or paste the things you needed to keep from the old class.
I have not tested the above and have no idea if it would work, so I really recommend backing your database up before you try it. If you do try it, let me know how it works out.
- Gregor
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Chris McDonough Digital Creations, Inc. Zope - http://www.zope.org
----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com>
AFAIK, there is no approved way to add a base class to an existing ZClass. I've heard from other people at DC that it is possible, but it's a "hold on to your butts" experience. That said, I have no idea whether Gregor's method will work or not.
I should point out that Gregor has been using Zope for less than 2 weeks, so Gregor can hardly be considered likely to come up with something that works... ^_^ I'm just thinking out loud, mostly. - Gregor
BTW, the preferred workaround for this (for now) is to create an empty Python base class someplace before you develop your ZClass and inherit from it when you create the ZClass. That way, if you need to inherit from a different class later, you can wedge it into the empty Python base class. An example of a Python module with an empty base class: class MyZClassBase: pass An example of such a module when the base class has added inheritance: import OFS.ObjectManager class MyZClassBase(OFS.ObjectManager): pass You can import this module and the class into Zope by creating a Zope Product that includes a call to registerBaseClass in its __init__.py for the class under which you'd like to subclass your ZClass. See Amos' Product API Tutorial and gtk's Boring product and related HOWTO for examples. Chris McDonough wrote:
AFAIK, there is no approved way to add a base class to an existing ZClass. I've heard from other people at DC that it is possible, but it's a "hold on to your butts" experience. That said, I have no idea whether Gregor's method will work or not.
-- Chris McDonough Digital Creations, Inc. Zope - http://www.zope.org
I have not tried the wildly unsupported method... I'm not brave enough. I have, however, used the method that Gregor describes. It is a little tedious, but it works just fine. Broken down step-by-step, I think this is what I've done: 1) Rename the old classes and their metatypes to something like MyClass2, MyType2 2) Create a new ZClass with the proper base classes. 3) Start copying and pasting your methods and such... rebuild your propertysheets. This is the tedious part. It's probably a good idea to make sure you look at every tab in the management interface to make sure you don't miss something. 4) Copy your original ZClass' class ID to the clipboard. Then change the class ID to something else. (I typically just add an extra = on the end) 5) Change the new ZClass' class ID to the one on the clipboard. Voila! New ZClass. I think Chris' suggestion from his next message (creating a Python base class) sounds really dandy. But, you'll probably want to use the above steps to get that base class into your existing ZClasses... Kevin ----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: "Gregor" <vorlon@iglou.com> Cc: <zope@zope.org>; <stevej@parlant.com> Sent: Sunday, January 09, 2000 11:00 PM Subject: Re: [Zope] Adding another base class to an existing ZClass
AFAIK, there is no approved way to add a base class to an existing ZClass. I've heard from other people at DC that it is possible, but it's a "hold on to your butts" experience. That said, I have no idea whether Gregor's method will work or not.
Gregor wrote:
----- Original Message ----- From: "Steve Jibson" <stevej@parlant.com> To: <zope@zope.org> Sent: Friday, January 07, 2000 6:22 PM Subject: [Zope] Adding another base class to an existing ZClass
I've spent many hours working on a ZClass (with multiple sub-zclasses, etc.), and now I've decided that I should have inherited from Folder
as
well as ObjectManager when I created the ZClass. Is there a way to add a base class to the base class list of an existing ZClass, or do I need to start all over?
Did anyone ever reply to this, or are you still trying to figure it out?
I've seen something in the Zope how-tos or guides about the "class id" field on the "basic" tab of the ZClass, and swapping out one ZClass for another.
I THINK the basic idea is that you would copy or export everything you want to keep (such as child ZClasses and methods) to a safe place, copy the ZClass's class id to a file somewhere, then delete the ZClass.
Create a new one with the same id, deriving from whatever you need. Then replace the new class's id with the one you saved in the file. Finally, re-import or paste the things you needed to keep from the old class.
I have not tested the above and have no idea if it would work, so I really recommend backing your database up before you try it. If you do try it, let me know how it works out.
Kevin Dangoor wrote:
I have not tried the wildly unsupported method... I'm not brave enough. I have, however, used the method that Gregor describes. It is a little tedious, but it works just fine. Broken down step-by-step, I think this is what I've done:
1) Rename the old classes and their metatypes to something like MyClass2, MyType2 2) Create a new ZClass with the proper base classes. . . . Since this is a rather simple procedure, why can't Zope do this autmatically using a Base Classes dialog? -- Itamar S.T. itamars@ibm.net
----- Original Message ----- From: "Kevin Dangoor" <kid@kendermedia.com> To: "Chris McDonough" <chrism@digicool.com>; "Gregor" <vorlon@iglou.com>
3) Start copying and pasting your methods and such... rebuild your propertysheets. This is the tedious part.
Only the property sheets of the class you are changing really have to be rebuilt, and this is only because Zope doesn't support cutting or copying Property Sheets (why?). It does support Exporting them, but as far as I can tell, Importing them is not supported (which seems weird) or works counter-intuitively. So let's see if we can't formalize the process for a How-To (unless there's one already up that I haven't seen): Parent: The ZClass that you need to change base classes for. ParentMetaType: The Meta Type of Parent, available on the "Basic" tab. ParentID: The actual name/ID of Parent (as opposed to the literal word "Parent"). Not to be confused with ParentClassID. ParentClassID: The garbage in the "class id" field of Parent's "Basic" tab. Looks something like "yf14F2CKDLkO79P4DnDeKw==" 0. Pack and Backup your database ;-) 1. Find and copy the current ParentClassID (using your computer's clipboard function) 2. Append an = to ParentClassID. 3. Append "old" to ParentMetaType. 4. Go to the object containing Parent. This will be your Product, if Parent is the topmost ZClass. We will call this object "Top". 5. Append _old to ParentID 6. Still in "Top", add a new ZClass. Give it the original ParentID, the base classes you need, and the original ParentMetaType. Uncheck the "Create Constructor Objects" box (these already exist; we never changed them). Halfway there! Henceforth, Parent will be referred to as OldParent, and the class you just made in step 6 will be called NewParent. 7. Go into NewParent's basic tab. Replace the current "class id" with the one you copied in step 1. 8. Go to OldParent's methods tab. Select everything, then hit cut. 9. Back to NewParent's methods tab. Paste. 10. Go look at the Property sheet(s) of OldParent. Reproduce these in NewParent. 11. Check the Views, Permissions, and Define Permissions tabs of OldParent, and make sure these are the same in NewParent. If applicable, do the same for "Subobjects" and whatever else your class had. 12. Set the icon of NewParent. You might need to fix the icons of any child classes (not sure). After you've made sure you've gotten everything out of it that you need, delete OldParent and enjoy. Well, I did that more or less as I wrote it, but I need a Zope Guru to look at it and go "Uh, you forgot this major issue" or whatever. ;-)
participants (5)
-
Chris McDonough -
Gregor -
Itamar Shtull-Trauring -
Kevin Dangoor -
Steve Jibson