[Zope] Add properties to ZClass instance?
Chris Muldrow
muldrow@mac.com
Fri, 30 Mar 2001 11:21:29 -0500
In the propertysheets.py file in the Zope Source, you'll find some help for
modifying and adding properties programmatically. I've included an example
Credit goes to Tazzzzz at http://www.zope.org/Members/tazzzzz/addZClasses
for getting me started.
def addFLSNews(newdir, newid, data, newtitle, REQUEST=None):
""" """
# This sucks in some data from Zope to form the body of the ZClass.
# It also grabs an id, title and a directory
# This creates a new object of Zclass FLSNewsStory using the data
inside your chosen directory
newob=newdir.Control_Panel.Products.FLSNewsStory.FLSNewsStory(data)
# This sets the id of the object
newob._setId(newid)
# this actually sets the object
newdir._setObject(newid, newob)
# this sets the title of the object
newob.title=newtitle
# this is a second function that parses the data to get a value called
Author
# the getAuthor part is unimportant to this discussion--just know a
value is set for the variable varAuthor
varAuthor=getAuthor(data)
# this sets a property in the FLSNewsProperties propertysheet of
FLSNewsStory called Byline to the value of varAuthor
newob.propertysheets.FLSNewsProperties.manage_changeProperties({'Byline':var
Author})
# if your Zclass doesn't already have properties attached, you can
also use something like newob._setProperty('Byline', varAuthor,
type='string') to set a property in the basic property sheet and something
like this: newob._updateProperty('Byline', varAuthor) to update a property
that exists
Now somebody who's a better Zoper than I can check and see where I screwed
up this explanation!
-- Chris Muldrow, muldrow@mac.com
> From: "Paul Godley" <pdg@tcdi.com>
> Date: Thu, 29 Mar 2001 17:32:02 -0500
> To: <zope@zope.org>
> Subject: [Zope] Add properties to ZClass instance?
>
> I've got a ZClass to which I'd like to add (variable) properties when
> the instance is created. I made a "Basic" propertysheet and tried
> "manage_addProperty" but Zope reports that properties cannot be added. I
> can add properties to DTML Documents.
>
> Can you construct a ZClass such that you can add properties to an
> instance, both via management screens and programatically?
>
> Thanks.
>
> -P
>
> --
> Technology Concepts & Design, Inc.
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )