Accessing default properties on addObjectForm
I wish to look at default properties of my custom object when creating the addObjectForm. There is any way to do this? Something like: <dtml-var "Products.MyProduct.Custom.default_title"> Thanx. -- Sidnei da Silva X3ng Consultoria e Desenvolvimento Ltda. sidnei@x3ng.com.br
Sidnei da Silva writes:
I wish to look at default properties of my custom object when creating the addObjectForm.
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ürther objects in the product. Look at the code in "App.ProductDispatcher" (maybe "App.FactoryDispatcher", or something like that), for details. Dieter
Ok. Got it 70%. Just couldnt get about the constructor. Is this something like the definition of manage_addProduct, that is done outside the class definition because the class instance was not created yet? See ya'. Em Tuesday 30 October 2001 07:51, Dieter Maurer escreveu:
Sidnei da Silva writes:
I wish to look at default properties of my custom object when creating the addObjectForm.
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ürther objects in the product. Look at the code in "App.ProductDispatcher" (maybe "App.FactoryDispatcher", or something like that), for details.
Dieter
-- Sidnei da Silva X3ng Consultoria e Desenvolvimento Ltda. sidnei@x3ng.com.br
Sidnei da Silva writes:
Ok. Got it 70%. Just couldnt get about the constructor. Is this something like the definition of manage_addProduct, that is done outside the class definition because the class instance was not created yet? Inside your products "__init__.py" you call
context.registerClass(..., constructors=(C1,C2,...), ....) The first constructor ("C1" above) is used as target in the corresponding "AddList" slot. All constructors are protected by the products "Create" permission. They can be accessed via the product dispatcher (the thing returned by "manage_addProduct[<productname>]"). That's all one can say about Zope's product constructors.... Dieter
participants (2)
-
Dieter Maurer -
Sidnei da Silva