[Zope3-dev] Add item blues...

Garrett Smith garrett@mojave-corp.com
Wed, 2 Jul 2003 10:35:01 -0500


I'm so excited -- I finally get to *answer* a question ;-)

You need to create your own 'Adding' class and use it, instead of the
default, in the 'Add' menu item for your Foo folders.

For the steps below, I'm assuming this:

  class IFoo(IFolder):
      pass

  class Foo(Folder):
      implements(IFoo)

Step 1 - Create an Adding subclass:

  from zope.app.browser.container.adding import Adding
  class FooAdding(Adding): =20
      menu_id =3D "add_bar"

Here, you're overriding Adding's menu_id, which is used to grab the menu
items it displays.

Step 2 - Install your new Adding class as the '+' view for IFoo:

  <view
      for=3D"IFoo"
      name=3D"+"=20
      menu=3D"zmi_actions"=20
      title=3D"Add"
      class=3D"FooAdding"
      permission=3D"zope.ManageContent">

      <page name=3D"index.html"  attribute=3D"index" />
      <page name=3D"action.html" attribute=3D"action" />

   </view>

Note the two page subdirectives -- these point to the index and action
attributes of Adding, which reuse the appropriate templates and logic.

With this pattern, you're replacing the default adding mechanism only
for instances of IFoo. You're reusing all of the adding logic and
overriding only 'menu_id'.

Kudos to the Z3 team -- this is a good example of Z3's outstanding reuse
support.

 -- Garrett


Adam Summers wrote:
> Hi,
>=20
> I have a product which uses folder as a base class:
>=20
> class Foo(Folder):
>=20
> .. and in the configure.zcml I set this up:
>=20
>     <browser:page
>         name=3D"contents.html"
>         menu=3D"zmi_views" title=3D"Contents"
>         for=3D".interfaces.IFoo"
>         permission=3D"zope.ManageContent"
>         class=3D"zope.app.browser.container.contents.Contents"
>         attribute=3D"contents" />
>=20
> ..  and I also define a menu:
>=20
>     <browser:menu
>         id=3D"add_bar"
>         title=3D"bar items" />
>=20
>     <browser:menu
>         id=3D"bar_actions"
>         title=3D"bar actions" />
>=20
> ...and have a bar object definition with its own addform
>=20
>     <browser:addform
>         schema=3D".interfaces.IBar"
>         label=3D"Add Bars"
>         content_factory=3D".bar.Bar"
>         fields=3D"wid get"
>         name=3D"Add Bar"
>         menu=3D"add_bar" title=3D"Bar info"
>         permission=3D"zope.ManageContent" />
>=20
> My question is this: What do I have to do, so that when I look at the
> contents of the folder, the "Add new Content Menu" contains an option
> to add a bar (and only that option)? I would be grateful for any
> pointers.=20