Re: [Zope-dev] Making a custom class addable to another class in product, but not to Zope

2004-02-25 Thread Leonardo Rochael Almeida
Anoter option is to register a container_filter for the Thing class:

def initialize(context):
(...)
context.registerClass(thingmodule.Thing,
  permission=thingmodule.ADD_THING_PERMISSION,
  constructors=(...),
  container_filter=thingmodule.containerFilter,
  icon="www/thing.png")

where containerFilter is a module global function that could be:

def containerFilter(container):
isinstance(container, containermodule.Container)

This way Zope doesn't show it as addable to anything on the management
interface except Containers. I don't think Zope checks the
container_filter if the constructors are invoked directly, eg. by a
PythonScript, but if you want to be strict, you can invoke the
containerFilter again on the constructors and raise an exception...

Cheers, Leo.

On Wed, 2004-02-25 at 17:52, Dieter Maurer wrote:
> Ian Beatty wrote at 2004-2-24 17:33 -0500:
> > ...
> >I've got
> >two classes in my product; let's call them Container and Thing. I want to
> >have Container addable to any old folder in the ZMI; that's no problem, I
> >just register it in my product's __init__.py file. I want Container to allow
> >instances of Thing to be added to it, and nothing else; that's also no
> >problem, using all_meta_types.
> >
> >However, I want Thing to be addable to Container, but not to any other
> >ObjectManager-based object.
> 
> You simply do not register "Thing".
> You define "constructors" (they are factories indeed, but
> Zope uses the term "constructors") for "Thing" on "Container",
> among them the "construtor" for the action you used
> in "all_meta_types".
> 
> Your "all_meta_types" will return something like:
> 
> (
>   {
>   'name' : 'Thing',
>   'action': 'Thing_add',
>   'permission': ManagePortal,
>   },
>   )
> 
> Note, there is not "manage_addProduct" in the action...
-- 
Leonardo Rochael Almeida <[EMAIL PROTECTED]>

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Making a custom class addable to another class in product, but not to Zope

2004-02-25 Thread Dieter Maurer
Ian Beatty wrote at 2004-2-24 17:33 -0500:
> ...
>I've got
>two classes in my product; let's call them Container and Thing. I want to
>have Container addable to any old folder in the ZMI; that's no problem, I
>just register it in my product's __init__.py file. I want Container to allow
>instances of Thing to be added to it, and nothing else; that's also no
>problem, using all_meta_types.
>
>However, I want Thing to be addable to Container, but not to any other
>ObjectManager-based object.

You simply do not register "Thing".
You define "constructors" (they are factories indeed, but
Zope uses the term "constructors") for "Thing" on "Container",
among them the "construtor" for the action you used
in "all_meta_types".

Your "all_meta_types" will return something like:

(
  {
  'name' : 'Thing',
  'action': 'Thing_add',
  'permission': ManagePortal,
  },
  )

Note, there is not "manage_addProduct" in the action...

-- 
Dieter

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Making a custom class addable to another class in product, but not to Zope

2004-02-25 Thread Chris Withers
Ian Beatty wrote:

manage_addProduct['MyProduct'] accesses. Is there a way around this? I'd
think what I'm trying to do is pretty standard, but I can't find anything
enlightening.
Have a look at the code in the PlugginIndexes product tha tships with Zope, 
since it works in exactly the way you describe...

cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
   - http://www.simplistix.co.uk
___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )