[Zope-dev] Z Classes hangup.
Jim Fulton
jim@digicool.com
Tue, 11 May 1999 16:59:10 +0000
"Jeff K.Hoffman" wrote:
>
> I need to be able to create the following setup:
>
> Z Class:
> + MyBaseClass (inherits ObjectManager, isFolderish)
> Methods:
> - index_html (DTML Method)
> - doc_a (DTML Method)
> - doc_b (DTML Method)
>
> where index_html is:
>
> <!--#var doc_a-->
> <!--#var doc_b-->
>
> and doc_a is:
>
> This is Base Document A.
>
> and doc_b is:
>
> This is Base Document B.
>
> Now, when I make the following (in Zope Management interface):
>
> + / (Root Folder)
> - MyBaseClassInstance (MyBaseClass)
>
> I can browse to http://localhost/MyBaseClassInstance/index_html and see:
>
> This is Base Document A.
> This is Base Document B.
>
> So far so good. Now, here's where I am having problems. I need to override
> doc_a in the INSTANCE ONLY, like:
>
> + / (Root Folder)
> + MyBaseClassInstance (MyBaseClass)
> - doc_a (DTML Method)
>
> where doc_a is:
>
> This is Instance Document A.
>
> such that navigating to http://localhost/MyBaseClassInstance/index_html
> yields:
>
> This is Instance Document A.
> This is Base Document B.
>
> When I try to drop doc_a (DTML Method) in MyBaseClassInstance I get a "Bad
> Request" message, telling me the id doc_a is already in use. :(
>
> I don't want to have to make a new Z Class, and I don't want to mess with
> index_html or doc_b at all (though I may, in another instance, want to change
> index_html to reverse the order of doc_a and doc_b, or just redefine doc_b
> instead, etc. Each instance will be unique. Changing the base class should
> change all instances, except those which have overloaded the changed aspect.
> As I understand it, Z Classes already do this just fine.)
The ObjectManager class doesn't let you add an object if the
id of the new object matches the name of an existing attribute. This
is not just true of ZClasses instances, it is true of folders and
other object managers. This is a feature.
I suppose you could create a mix-in class that provided a
_checkId that was less restrictive. You'd want to allow the
object to be added if the object didn't aleady have the id
as a key in it's instance dictionary and if the name was in some
list of overridable names.
Alternatively, you could try one of the following approaches:
1. Ommit doc_a from the class and make it's insertion
conditional:
<!--#if "_.hasattr(aq_explicit, 'doc_a')"-->
<!--#var doc_a-->
<!--#else-->
<!--#var default_doc_a-->
<!--#/if-->
2. Ommit doc_a from the class and create it in the
instance during construction:
<!--#with "theClass.index_html(REQUEST['id'], REQUEST)"-->
<!--#call "manage_addDTMLDocument(
'doc_a','',
'<!--#var default_doc_a-->')"-->
<!--#/with-->
> If only I can get this to work, my company will be using Zope on two MAJOR
> deals we just got.
Cool.
> This is the only hitch in our gitty-up at the moment. How frustrating to be
> sooo close. :^) HEEELP! :^)
I hope you are just prototyping at this point. ZClasses have some
*current* limitations that make them risky for production
applications. In particular:
- If a ZClass instance is exported and imported, it will be
disconnected from the class in Products, because the class
gets exported to. In other words, the instance will have a
*copy* of the class.
- Because copy and paste use the same machinery as export/import,
copy and paste have the same problem as described above.
We plan to fix this ASAP, but it probably won't get fixed till
the end of May or early June.
Jim
--
Jim Fulton mailto:jim@digicool.com
Technical Director (540) 371-6909 Python Powered!
Digital Creations http://www.digicool.com http://www.python.org
Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission. Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.