[Zope] Re: selection list confusion ...
Jim Washington
jwashin@vt.edu
Sun, 13 Feb 2000 12:31:38 -0500
Hi, Darran
Darran Edmundson wrote:
>
> Thanks Jim,
>
> >If you are doing this within a ZClass, you can put Choices on a
> >PropertySheet, then refer to it as
> >
> ><dtml-in Choices>
>
> As I understand it though, Zope does not have class variables.
> If Choices is on a property sheet each instance will have
> its own copy which seems like needless bloat.
My zope installation seems to act as if the values in the class property
sheets are class variables.
Try this:
In your zClass, make a property sheet called 'MyClassGlobals'
On that sheet, put in a property of type 'lines' called
'MyClassSelections'.
Put in the values
one
two
three
In your zClass's methods, make a dtml method called 'showselections'
that looks like:
<ul>
<dtml-in MyClassSelections>
<li><dtml-var sequence-item></li>
</dtml-in>
</ul>
Now, make an index_html DTML method in your zclass's methods (or edit
your existing one).
Within that method, put <dtml-var showselections>.
Now go somewhere in your site and create an instance of your zClass
called 'test'. View it by opening http://[mysite][/path]/test.
It should have
* one
* two
* three
Now, go back to the ZClass and change the values in MyClassSelections:
Bob
Mary
Fred
View the previously-created test instance again.
In my experience, it will now show
* Bob
* Mary
* Fred
This seems to have the behavior of a class variable, no? If
MyClassSelections were copied into the new instance, it should still
show *one *two *three, but it doesn't. I presume that these values are
acquired unless overridden in the instance.
So, what you may want to do is have a 'MyClassGlobals' property sheet
with the information that want to be global for all instances of the
zClass, and make it changeable only within the zClasses structure, i.e.,
do not make a 'view' of it, so it cannot ordinarily be overridden.
Then, you can have a visible property sheet that makes use of these
globals.
For example, in another property sheet, make a property with an id of
'MyChoice' with type 'selection' and a value of 'MyClassSelections'.
Zope will display that it has 'No value', which is a bit misleading,
since it will show the list within an instance of the ZClass. Assure
this property sheet is visible in the management interface by making a
'view' of it.
Now, within that tab of the management interface for an item of that
class, you should have a select item that has the values from
MyClassSelections on the MyClassGlobals sheet.
You may ask, what happens if you make a selection, then change the
selection list so that the selection is no longer valid on the globals
property sheet. The answer is that Zope will store the value as a
string, and hold on to it unless changed. Also, you must be sure that
the values on that sheet get saved at least once for each instance or
that MyChoice gets initialized programmatically with a default value,
since (even though it may display the first item in the list) MyChoice
will have an initial value of 'None' until saved.
>
> Ideally, what I'd like to do is either of the following.
> Imagine I have the following ZODB hierarchy:
>
> root
> Control_Panel
> Products
> MyClassProduct
> MyClass
> Properties
> - MakeChoice (type selection)
> globals
> - GetChoices (DTML method)
>
> 1) I would like the value field of MakeChoice to call the DTML
> method GetChoices which resides in the globals folder. As
> it stands, GetChoices needs to live in the root in order
> to be found by acquisition. Is there a way around this?
>
> Alternatively,
>
> 2) I would like GetChoices to live in MyClassProduct.
> This does not work for reasons that elude me. One would naively
> think that since GetChoices is in the same location as both
> the class addForm and the constructor, it would be found by
> acquisition. It isn't.
AFAIK, your class's methods should be inside the zClass within its
methods area, not in the Product area, where the addForm is.
>
> Any clarification of these issues would be most appreciated.
I am not sure I answer all your questions, so if I am off-base, I will
be happy to try again. But for the moment I will assume that a
class-variables-ish solution is what you are looking for.
Regards,
-- Jim Washington