'selection' and 'multiple selection' property types
Is there an example anywhere of how to use these? I am looking in ZPublisher/Converters.py (2.0a3) and they are not defined there. Are these property types not implemented yet? Alex Rice | alrice@swcp.com | http://www.swcp.com/~alrice Current Location: N. Rio Grande Bioregion, Southwestern USA
At 20:48 05/07/99 , Alex Rice wrote:
Is there an example anywhere of how to use these? I am looking in ZPublisher/Converters.py (2.0a3) and they are not defined there. Are these property types not implemented yet?
They are, for displaying a list as a SELECT field. It is very limited, you can only use it for one field per propertysheet, but here goes: If you have a tokens or lines property, lets call it 'colours_list', you can display a SELECT list on your propertysheet by defining a property called 'select_variable', type string, set to 'colours_list', and a variable named, lets say, 'colours', type selection or multiple selection. If you choose type 'selection', 'colours' will one value out of the 'colours_list' list, which the user of the propertysheet can select from a drop-down box. If you choose type 'multiple selection', 'colours' will hold a list of 0 or more values from the 'colours_list' list, which the user can select from the scrolling list. The height of the listbox is either 7 or the number of elements in 'colour_list', whichever is the smallest. Personally, I'd like it to be more flexible on what list property is being used to fill the drop-down list or listbox. Maybe, for a (multiple) selection property named xxx, you should define a text property named xxx_select_variable. This way you can have more than one (multiple) selection property on any given propertysheet. Example: // The following four vars could be defined on a seperate // propertysheet without a public view colours_list (tokens) = "red yellow green blue" colours_select_variable (string) = "colours_list" sizes_list (tokens) = "smallest small smaller medium larger large largest" sizes_select_variable (string) = "sizes_list" // These property defined on a public propertysheet colours (selection) = "red" (populated from 'colours_list') sizes (selection) = "medium" (populated from 'sizes_list'). Patch to properties.dtml to support this: *** properties.dtml~ Wed Jul 7 15:37:41 1999 --- properties.dtml Wed Jul 7 16:18:08 1999 *************** *** 64,72 **** "getProperty(id)"--><!--#var sequence-item--><!--#if sequence-end--><!--#else--><!--#var "'\n'"--><!--#/if--><!--#endin--></textarea> <!--#elif "type=='selection'"--> ! <!--#if "_.has_key(select_variable)"--> <select name="<!--#var id-->"> ! <!--#in "_[select_variable]"--> <option <!--#if "_['sequence-item']==getProperty(id)"-->SELECTED<!--#/if--> ><!--#var sequence-item--></option> --- 64,72 ---- "getProperty(id)"--><!--#var sequence-item--><!--#if sequence-end--><!--#else--><!--#var "'\n'"--><!--#/if--><!--#endin--></textarea> <!--#elif "type=='selection'"--> ! <!--#if "_.has_key(_[id + '_select_variable'])"--> <select name="<!--#var id-->"> ! <!--#in "_[_[id + '_select_variable']]"--> <option <!--#if "_['sequence-item']==getProperty(id)"-->SELECTED<!--#/if--> ><!--#var sequence-item--></option> *************** *** 73,90 **** <!--#/in--> </select> <!--#else--> ! No value for <!--#var select_variable--> <!--#/if--> <!--#elif "type=='multiple selection'"--> ! <!--#if select_variable--> <select name="<!--#var id-->:list" multiple ! size="<!--#var "_.min(7, _.len(_[select_variable]))"-->"> ! <!--#in "_[select_variable]"--> <option<!--#if "_['sequence-item'] in getProperty(id)"--> SELECTED<!--#endif -->><!--#var sequence-item--></option> <!--#/in--> </select> <!--#/if--> <!--#else--> <em>Unknown property type</em> --- 73,92 ---- <!--#/in--> </select> <!--#else--> ! No value for <!--#var "_[id + 'select_variable']"--> <!--#/if--> <!--#elif "type=='multiple selection'"--> ! <!--#if "_.has_key(_[id + '_select_variable'])"--> <select name="<!--#var id-->:list" multiple ! size="<!--#var "_.min(7, _.len(_[_[id + '_select_variable']]))"-->"> ! <!--#in "_[_[id + '_select_variable']]"--> <option<!--#if "_['sequence-item'] in getProperty(id)"--> SELECTED<!--#endif -->><!--#var sequence-item--></option> <!--#/in--> </select> + <!--#else--> + No value for <!--#var "_[id + 'select_variable']"--> <!--#/if--> <!--#else--> <em>Unknown property type</em> -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
On Wed, 07 Jul 1999 16:32:08 +0200, Martijn Pieters <mj@antraciet.nl> said: Martijn> They are, for displaying a list as a SELECT field. It is very Martijn> limited, you can only use it for one field per propertysheet, Martijn> but here goes: Cool! You are really good at explaining this stuff, Martijn. I also learned a lot from your earlier post about inheriting from Object Manager. Thanks... Martijn> Personally, I'd like it to be more flexible on what list Martijn> property is being used to fill the drop-down list or Martijn> listbox. Maybe, for a (multiple) selection property named xxx, Martijn> you should define a text property named Martijn> xxx_select_variable. This way you can have more than one Martijn> (multiple) selection property on any given propertysheet. Yes! This would be definitely helpful. Martijn> Patch to properties.dtml to support this: I'm not very experienced with diff and friends, but I can't apply this patch. I tried it against 2.0a3 and the latest CVS version... oh, properties.dtml hasn't changed recently anyways :-) Am I applying it wrong? My properties.dtml is 5169 bytes. [alex@monsoon OFS]$ patch --verbose -p0 < properties.dtml.patch Hmm... Looks like a new-style context diff to me... The text leading up to this was: -------------------------- |*** properties.dtml~ Wed Jul 7 15:37:41 1999 |--- properties.dtml Wed Jul 7 16:18:08 1999 -------------------------- Patching file `properties.dtml' using Plan A... Hunk #1 FAILED at 64. Hunk #2 FAILED at 73. 2 out of 2 hunks FAILED -- saving rejects to properties.dtml.rej Hmm... Ignoring the trailing garbage. done Alex Rice | alrice@swcp.com | http://www.swcp.com/~alrice Current Location: N. Rio Grande Bioregion, Southwestern USA
At 08:17 08/07/99 , Alex Rice wrote:
Cool! You are really good at explaining this stuff, Martijn. I also learned a lot from your earlier post about inheriting from Object Manager. Thanks...
You're welcome.
I'm not very experienced with diff and friends, but I can't apply this patch. I tried it against 2.0a3 and the latest CVS version... oh, properties.dtml hasn't changed recently anyways :-) Am I applying it wrong? My properties.dtml is 5169 bytes.
[alex@monsoon OFS]$ patch --verbose -p0 < properties.dtml.patch Hmm... Looks like a new-style context diff to me... The text leading up to this was: -------------------------- |*** properties.dtml~ Wed Jul 7 15:37:41 1999 |--- properties.dtml Wed Jul 7 16:18:08 1999 -------------------------- Patching file `properties.dtml' using Plan A... Hunk #1 FAILED at 64. Hunk #2 FAILED at 73. 2 out of 2 hunks FAILED -- saving rejects to properties.dtml.rej Hmm... Ignoring the trailing garbage. done
Ermm.. I could *&*^%$& IRIX diff... Try the attached file -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
On Wed, 07 Jul 1999 16:32:08 +0200, Martijn Pieters <mj@antraciet.nl> said: Martijn> If you have a tokens or lines property, lets call it Martijn> 'colours_list', you can display a SELECT list on your Martijn> propertysheet by defining a property called 'select_variable', Martijn> type string, set to 'colours_list', and a variable named, lets Martijn> say, 'colours', type selection or multiple selection. Martijn> If you choose type 'selection', 'colours' will one value out of Martijn> the 'colours_list' list, which the user of the propertysheet Martijn> can select from a drop-down box. Martijn> If you choose type 'multiple selection', 'colours' will hold a Martijn> list of 0 or more values from the 'colours_list' list, which Martijn> the user can select from the scrolling list. The height of the Martijn> listbox is either 7 or the number of elements in 'colour_list', Martijn> whichever is the smallest. What do you enter for the initial value when creating a property of 'multiple selection' type? Martijn> Personally, I'd like it to be more flexible on what list Martijn> property is being used to fill the drop-down list or Martijn> listbox. Maybe, for a (multiple) selection property named xxx, Martijn> you should define a text property named Martijn> xxx_select_variable. This way you can have more than one Martijn> (multiple) selection property on any given propertysheet. I definitely vote for something like this being included in Zope-- most non-trivial ZClasses will likely need more than one selection property! Martijn> Patch to properties.dtml to support this: Not sure why the patch would not patch, but after you mailed me your properties.dtml, it became obvious your approach. This works perfectly for normal objects (like DTML Docs) However, this *doesn't* work with ZClasses, and I'm not sure why not. Any ideas? It's as if _.has_key() is not working correctly for ZClasses. Here is what I did: 1) Apply your version of lib/python/OFS/properties.dtml, restart zope 2) Create Product 'Colors' 3) In Colors, add ZClass 'color' 4) In color add a propertysheet 'info' 5) In info, add tokens property colors_list = "red green blue" 6) Add string property colors_select_variable = "colors_list" [ now colors_select_variable definitely exists and is displayed] 7) Add selection property colors = "red" <!-- Traceback (innermost last): File /usr/share/Zope-2.0.0a4-src/lib/python/ZPublisher/Publish.py, line 256, in publish_module File /usr/share/Zope-2.0.0a4-src/lib/python/ZPublisher/Publish.py, line 161, in publish File /usr/share/Zope-2.0.0a4-src/lib/python/ZPublisher/mapply.py, line 154, in mapply (Object: manage_addProperty) File /usr/share/Zope-2.0.0a4-src/lib/python/ZPublisher/Publish.py, line 98, in call_object (Object: manage_addProperty) File /usr/share/Zope-2.0.0a4-src/lib/python/OFS/PropertySheets.py, line 406, in manage_addProperty (Object: info) File /usr/share/Zope-2.0.0a4-src/lib/python/App/special_dtml.py, line 120, in __call__ (Object: manage) File /usr/share/Zope-2.0.0a4-src/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__ (Object: manage) File /usr/share/Zope-2.0.0a4-src/lib/python/DocumentTemplate/DT_In.py, line 689, in renderwob (Object: propertyMap) File /usr/share/Zope-2.0.0a4-src/lib/python/DocumentTemplate/DT_Util.py, line 315, in eval (Object: _.has_key(_[id + '_select_variable'])) File <string>, line 0, in ? File /usr/share/Zope-2.0.0a4-src/lib/python/DocumentTemplate/DT_Util.py, line 150, in careful_getitem KeyError: colors_select_variable --> TIA -- Alex Rice | alrice@swcp.com | http://www.swcp.com/~alrice Current Location: N. Rio Grande Bioregion, Southwestern USA
At 23:52 16/07/99 , Alex Rice wrote:
Martijn> If you choose type 'multiple selection', 'colours' will hold a Martijn> list of 0 or more values from the 'colours_list' list, which Martijn> the user can select from the scrolling list. The height of the Martijn> listbox is either 7 or the number of elements in 'colour_list', Martijn> whichever is the smallest.
What do you enter for the initial value when creating a property of 'multiple selection' type?
You can't, I filed a bugreport for this. Can't remember what workaround I used.
Martijn> Patch to properties.dtml to support this:
Not sure why the patch would not patch, but after you mailed me your properties.dtml, it became obvious your approach. This works perfectly for normal objects (like DTML Docs) However, this *doesn't* work with ZClasses, and I'm not sure why not. Any ideas? It's as if _.has_key() is not working correctly for ZClasses. Here is what I did:
1) Apply your version of lib/python/OFS/properties.dtml, restart zope 2) Create Product 'Colors' 3) In Colors, add ZClass 'color' 4) In color add a propertysheet 'info' 5) In info, add tokens property colors_list = "red green blue" 6) Add string property colors_select_variable = "colors_list"
[ now colors_select_variable definitely exists and is displayed]
7) Add selection property colors = "red"
Bother. I had a feeling this wouldn't work. DC, can you make this work? -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
participants (2)
-
Alex Rice -
Martijn Pieters