[Zope] Class variables in ZClasses

Jim Fulton jim@digicool.com
Thu, 02 Dec 1999 14:46:40 +0000


Darran Edmundson wrote:
> 
(snip)
> I'm confused about how class variables are implemented in
> Zope. 

I prefer to call these shared instance attributes.


> For example, let's say I have a ZClass with instance
> variable "Subject" which is a list of keys into a dictionary
> "SubjectChoices".  Rather than every instance maintaining a
> separate copy, SubjectChoices should be a class variable -
> all instances see the same dictionary.  Any insights would
> be most appreciated.

You simply have to arrange to get SubjectChoices to be an 
attribute of the class managed by the ZClasses.  If there
was a way to create dictionary properties, you could do this
via a propertysheet, since ZClass propertysheets create
default property values in classes.  Since Zope doesn't
give you a way to spell this through the web, you have to resort
to Python.  You could define a Python mix-in class that has
the property:

  class MixIn:

     SubjectChoices={...}

and mix it into your ZClass.

Alternatively, you could, from Python (either using the
Python interactive interpreter or an external method do
something like:

  import Zope
  app=Zope.app()
  app.Control_Panel.yourProduct.yourZClass.setClassAttr(
     'SubjectChoices',{...})
  get_transaction().commit()
  app._p_jar.close()

Jim


--
Jim Fulton           mailto:jim@digicool.com
Technical Director   (888) 344-4332              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.