Re: [Zope-dev] Manipulating Meta-Type Global Add list on per-instance basis
Hmm... possibly I did not explain my needs : What I need to do is manipulate the attribute of a "folderish" object ( ie. an object that can contain other objects ) that determines what objects are allowed to be contained by my object. I need to do this at instantiation time , *NOT* definition time. I seemed to have accomplished this by manipulating the "meta_types" attribute... but is this a valid way to attain this behavior? thanks again- Josh
Josh Zeidner <jmz_phylogenic@hotmail.com> asks:
I am currently trying to define a Z-Class that inherits from Object Manager that has the special behavior of being able to change its "allowable sub-objects" on a per-instance basis.
*****************
ex.
I instantiate the class at a particular location I want this object to only be able to contain objects of type "AppleObject" and "OrangeObject".
I instantiate the class at another location and I want this object to only contain objects of type "LemonObject" and "LimeObject".
note that the difference here is that both of the containers are of the same type.
*************
is it possible to have this flexibility after the ZClass has been defined?
If you are defining the interface (rather than accepting the default "Contents" view), then you can do something like::
<select name="toAdd"> <dtml-in "filtered_meta_types( AUTHENTICATED_USER )" mapping> <dtml-if "name in allowed_types"> <option value="&dtml-name;"> <dtml-var name> </dtml-if> </dtml-in> </select>
where 'allowed_types' is a tokens/lines property of the instance.
Making this happen in the stock management interface is trickier -- you need to overried either all_meta_types(), but finding the list of possible types, so that the list you return contains the dictionaries required by filtered_meta_types(). I can't see easily off hand how to do this from within a Python Method -- I think I would have to drop down to an External Method, or create a new Python base class to implement this.
Tres. -- ========================================================= Tres Seaver tseaver@palladion.com 713-523-6582 Palladion Software http://www.palladion.com
______________________________________________________ Get Your Private, Free Email at http://www.hotmail.com
Josh Zeidner wrote:
Hmm... possibly I did not explain my needs :
What I need to do is manipulate the attribute of a "folderish" object ( ie. an object that can contain other objects ) that determines what objects are allowed to be contained by my object. I need to do this at instantiation time , *NOT* definition time.
That is what I was targeting -- I guess my implementation wasn't limpidly transparent.
I seemed to have accomplished this by manipulating the "meta_types" attribute... but is this a valid way to attain this behavior?
That is a more straightforward option than I proposed below -- my code _filters_ the available meta_types based on a tokens/list instance property -- the catch is that you have to replace the standard "contents" view in order to get my code used (I am not really changing what _could_ be added; I merely change the list presented to the user.) Munging the meta_types attribute is actually an interesting idea -- "normal" Python product objects have the meta_types attribute as a class member; so in fact, you are "hiding" the class member when you assign to the instance attribute. If you ever want to "recover to original," you should be able to just "del self.meta_types" hand have it reappear, presto-changeo. Glad you found a solution. Tres. -- ========================================================= Tres Seaver tseaver@palladion.com 713-523-6582 Palladion Software http://www.palladion.com
participants (2)
-
Josh Zeidner -
Tres Seaver