[Zope] DTML Document Properties

Chris Withers chrisw@nipltd.com
Sun, 21 Apr 2002 10:02:19 +0100


Dan Shafer wrote:
> 
> LOL. OK,OK, I get it. Especially when I look and look and look and I can't
> see how to set custom-defined properties for an existing DTML Document
> object. It *appears* I have to create the DTML document in a script, then
> use the manage_addProperties function to add properties and assign values.
> Feels a tad indirect but I don't see property setters and getters.

Yeah, properties could have nicer interfaces...

Here's a little loop I use in my edit methods when only string properties are
used, assuming a form has been submitted that contains the properties you want
to set the values of:

REQUEST = context.REQUEST
for name in ['my_prop1','my_prop2']:
   update = {}
   value = REQUEST.get(name,'')
   if context.hasProperty(name):
     update[name]=value
   else:
     context.manage_addProperty(name,value,'string')
apply(context.manage_changeProperties,(),update)

cheers,

Chris