[Zope-CMF] Add property and assign value

Tres Seaver tseaver@palladion.com
Thu, 24 May 2001 08:33:58 -0400


Yoke May Seow wrote:

> Upon creation of a folder, I would like to assign a property called
> Folder_Name and assign a random value for it.
> 
> How can I automate this process without having to create it manually?


First, I would like to clarify:  do you want the "id" of the folder

(the "name" which shows up in its URL) to be (or contain) a random
value?  Or do you really want an additional property?

For the first requirement, you could customize the 'folder_factories'
skin method to generate a random id value and pass it as a hidden field,
e.g.:

   <dtml-let randID="_.whrandom.randint( 1, 1000 )">
    <input type="hidden" name="id" value="&dtml-randID;">
   </dtml-let>


For the second requirement, you will either need to create a new
Product with a "factory method" which adds the property, or else
switch to using a ScriptableTypeInformation object (which lets you
do the scripting inside the CMFSite).

A sample factory method might be:

   <dtml-let randID="_.whrandom.randint( 1, 1000 )">
   <dtml-with "manage_addProduct[ 'CMFDefault' ].addDocument( REQUEST[ 
'id' ] )">
     <dtml-call "manage_addProperty( 'Folder_Name', randID">
   </dtml-with>
   </dtml-let>

For more information on ScriptableTypeInformation objects, please see:

   http://cmf.zope.org/Members/tseaver/how_tos/taming_types_tool

Hope this helps!

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@digicool.com
Digital Creations     "Zope Dealers"       http://www.zope.org