[Zope] Accessing default properties on addObjectForm

Dieter Maurer dieter@handshake.de
Tue, 30 Oct 2001 22:51:26 +0100 (CET)


Sidnei da Silva writes:
 > I wish to look at default properties of my custom object when creating=
 the=20
 > addObjectForm.
 >=20
 > There is any way to do this? Something like:
 > <dtml-var "Products.MyProduct.Custom.default_title">
With

	<ObjectManager instance>.manage_addProduct[<Product Name>]

you get the product dispatcher for your product.

It has access to all product functions registered as "constructor"s.
Now, "constructor" is a misnomer: You can register any function
as a "constructor". Only the first "constructor" has a special
meaning: it is used as target in the "add" list...

This provides for the following solution:

  Define a function "getDefaults" in your product
  that returns a dictionary with the defaults.

  Register is as a constructor (not the first one!).

  Call it as "manage_addProduct['your product'].getDefaults()"
  and use the default values you need.

  Inside a constructor, you are already in the dispatcher context,
  thus you can directly call "getDefaults".


The factory dispatcher can access some specially declared f=FCrther
objects in the product. Look at the code in "App.ProductDispatcher"
(maybe "App.FactoryDispatcher", or something like that), for details.


Dieter