how-to: dynamically create a list for the Value of a zClass multiple-selection Type?
Or put another way! how-to: make the Value of a zClass multiple-selection Type property call the ID's of other zClasses in a Folder. i searched the boards and zope.org, but couldnt find references to using multiple-selection in zClasses. specifically: What is the syntax for the Value of a multiple-selection Type? -to build from the instances of a different zClass The DTML below generates the list I need, but what is the syntax that makes sense to Value in zClasses? is this DTML generating the right type of list? ###the_list DTMLMethod <dtml-with folder_of_anotherZClasses> <dtml-in expr="objectValues('anotherZClass')"> <dtml-var "id"> </dtml-in> </dtml-with> When I instantiate myzClass, one of the myzClass properties is a multiple-selection list of all the instances of 'anotherZClass', in a specified folder. I want the 'id' because a method of myzClass is to create hotlinks to related 'anotherZClass'. Thanks again for the support, -Trevor
Trevor Toenjes writes:
When I instantiate myzClass, one of the myzClass properties is a multiple-selection list of all the instances of 'anotherZClass', in a specified folder. I want the 'id' because a method of myzClass is to create hotlinks to related 'anotherZClass'. For properties of type "selection" or "multiple selection", the "Value" field is abused. It does not specify the initial property value but the so called "select_variable", in fact a misnomer! What you put into the value field is rendered to get the sequence of possible selection values. It can be, for example, the id of a property, the id of a method (DTML, external, whatever) or a (Python) script. When rendered (called), it must return a sequence. This sequence will be your selection values.
I recommend to write a Python script which returns the result of calling "objectIds" with appropriate variables. Use the script's id as value for your selection property. Dieter
My first attempt at a python script and the back-up DTMLMethod dont work. What am I doing wrong? Is there a cross-reference guide to learn Python scripts from a Zope perspective? (the learn Python books I have yet to immerse into are not in a Zope context.)
I recommend to write a Python script which returns the result of calling "objectIds" with appropriate variables. Use the script's id as value for your selection property.
I have tried this by placing the 'objectIds' in the Value field for /multiple selection/propertysheets/zClass. I get this error: Error Type: InError Error Value: Strings are not allowed as input to the in tag. ###DTMLMethod 'objectIds' /in zClass/methods <dtml-with folder_of_anotherZclass> <dtml-in expr="objectValues('anotherZclass')"> <dtml-var id> </dtml-in> </dtml-with> Q's: This works fine when rendering from a folder not in the zclass! why not a zclass? How do I convert to a list? Am I placing 'objectIds' in the wrong space? Python script Here is my attempt to convert this to a python script. What is the Python script equivalent to "dtml-with"? Error Type: NameError Error Value: global name 'folder_of_anotherZclass' is not defined ###Python script 'objectIds' /in zClass/methods myList=[] for id in folder_of_anotherZclass.objectValues('anotherZclass'): myList.append(id) return myList Thank you for the guidance, -Trevor
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Trevor Toenjes
My first attempt at a python script and the back-up DTMLMethod dont work. What am I doing wrong?
###DTMLMethod 'objectIds' /in zClass/methods
<dtml-in expr="objectValues('anotherZclass')"> <dtml-var id> </dtml-in> </dtml-with> This works fine when rendering from a folder not in the zclass! why not a zclass? How do I convert to a list? Am I placing 'objectIds' in the wrong space?
Why don't you just use the built in objectIds ??? <dtml-with folder_of_anotherZclass> <dtml-in "objectIds('anotherZclass')"> <dtml-var sequence-index> </dtml-in> </dtml-with>
What is the Python script equivalent to "dtml-with"? Error Type: NameError Error Value: global name 'folder_of_anotherZclass' is not defined
###Python script 'objectIds' /in zClass/methods myList=[] for id in folder_of_anotherZclass.objectValues('anotherZclass'): myList.append(id) return myList
for id in context.folder_of_anotherZclass.objectValues('anotherZclass'): myList.append(id) return myList "context" being "The current document or folder" you are in. But then again this method is not nessecary. For more info about the built in methods try the zope Book unde API, and se the objectManager class. regards Max
The DTMLMethod and Python script get the same error now. They are in the methods tab of 'myZclass'. ERROR: Cannot locate object at: http://zope/folder_of_myZclass/myZclass_instanceX
<dtml-with folder_of_anotherZclass> <dtml-in "objectIds('anotherZclass')"> <dtml-var sequence-index> </dtml-in> </dtml-with>
OR
myList=[] for id in folder_of_anotherZclass.objectValues('anotherZclass'): myList.append(id) return myList
With my newbie understanding, it looks like this is a namespace/traverse issue, which I cant resolve. The zClass is not renedering a DTMLMethod with DTML-with the same way as a DTMLMethod in the site. Why doesnt the DTML-with acquire folder_of_anotherZclass? Here is my structure: root ***using SiteRoot for Virtual Hosting |-folder_of_myZclass |-myZclass_instance1 |-myZclass_instance2 |-myZclass_instance3... |-folder_of_anotherZclass |-anotherZclass_instance1 |-anotherZclass_instance2 |-anotherZclass_instance3... I tried to force a path with ... <dtml-with expr="BASEPATH0.folder_of_anotherZclass"> -Trevor
Trevor Toenjes writes:
The DTMLMethod and Python script get the same error now. They are in the methods tab of 'myZclass'. ERROR: Cannot locate object at: http://zope/folder_of_myZclass/myZclass_instanceX Should Zope be able to locate the object there?
<dtml-with folder_of_anotherZclass> <dtml-in "objectIds('anotherZclass')"> <dtml-var sequence-index> </dtml-in> </dtml-with> This will return a string. Sure, you do not want that!
OR
myList=[] for id in folder_of_anotherZclass.objectValues('anotherZclass'): myList.append(id) return myList This should return a NameError unless you passed in "folder_of_anotherZClass" as parameter (what you did not as you can not pass parameters...).
Try: return context.folder_of_anotherZclass.objectIds('anotherZclass') Dieter
participants (3)
-
Dieter Maurer -
Max M -
Trevor Toenjes