Commit 575dfc86 authored by Amos Latteier's avatar Amos Latteier

Documented and fixed the creation of selection and multiple selection properties.

parent a7ce107d
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Property management""" """Property management"""
__version__='$Revision: 1.17 $'[11:-2] __version__='$Revision: 1.18 $'[11:-2]
import ExtensionClass, Globals import ExtensionClass, Globals
import ZDOM import ZDOM
...@@ -123,7 +123,13 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -123,7 +123,13 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
and a 'type' key. The 'id' key contains the name of the property, and a 'type' key. The 'id' key contains the name of the property,
and the 'type' key contains a string representing the object's type. and the 'type' key contains a string representing the object's type.
The 'type' string must be one of the values: 'float', 'int', 'long', The 'type' string must be one of the values: 'float', 'int', 'long',
'string', 'lines', 'text', 'date' or 'tokens'. 'string', 'lines', 'text', 'date', 'tokens', 'selection', or
'multiple section'.
For 'selection' and 'multiple selection' properties, there is an
addition item in the property dictionay, 'select_variable' which
provides the name of a property or method which returns a list of
strings from which the selection(s) can be chosen.
Each entry in the _properties structure may *optionally* provide a Each entry in the _properties structure may *optionally* provide a
'mode' key, which specifies the mutability of the property. The 'mode' 'mode' key, which specifies the mutability of the property. The 'mode'
...@@ -203,10 +209,20 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -203,10 +209,20 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
def _delPropValue(self, id): delattr(self,id) def _delPropValue(self, id): delattr(self,id)
def _setProperty(self, id, value, type='string'): def _setProperty(self, id, value, type='string'):
# for selection and multiple selection properties
# the value argument indicates the select variable
# of the property
if not self.valid_property_id(id): if not self.valid_property_id(id):
raise 'Bad Request', 'Invalid or duplicate property id' raise 'Bad Request', 'Invalid or duplicate property id'
self._properties=self._properties+({'id':id,'type':type},) if type in ('selection', 'multiple selection'):
self._setPropValue(id, value) if not hasattr(self, value):
raise 'Bad Request', 'No select variable %s' % value
self._properties=self._properties + (
{'id':id, 'type':type, 'select_variable':value},)
self._setPropValue(id, '')
else:
self._properties=self._properties+({'id':id,'type':type},)
self._setPropValue(id, value)
def _updateProperty(self, id, value): def _updateProperty(self, id, value):
# Update the value of an existing property. If value # Update the value of an existing property. If value
......
...@@ -79,10 +79,10 @@ values and click "Save Changes". ...@@ -79,10 +79,10 @@ values and click "Save Changes".
</dtml-in> </dtml-in>
</select> </select>
<dtml-else> <dtml-else>
No value for <dtml-var select_variable> No value for <dtml-var select_variable>.
</dtml-if> </dtml-if>
<dtml-elif "type=='multiple selection'"> <dtml-elif "type=='multiple selection'">
<dtml-if select_variable> <dtml-if "_.has_key(select_variable)">
<select name="<dtml-var id>:list" multiple <select name="<dtml-var id>:list" multiple
size="<dtml-var "_.min(7, _.len(_[select_variable]))">"> size="<dtml-var "_.min(7, _.len(_[select_variable]))">">
<dtml-in "_[select_variable]"> <dtml-in "_[select_variable]">
...@@ -91,6 +91,8 @@ values and click "Save Changes". ...@@ -91,6 +91,8 @@ values and click "Save Changes".
>><dtml-var sequence-item html_quote></option> >><dtml-var sequence-item html_quote></option>
</dtml-in> </dtml-in>
</select> </select>
<dtml-else>
No value for <dtml-var select_variable>.
</dtml-if> </dtml-if>
<dtml-else> <dtml-else>
<em>Unknown property type</em> <em>Unknown property type</em>
...@@ -133,7 +135,10 @@ To add a property, click the &quot;Add...&quot; button. ...@@ -133,7 +135,10 @@ To add a property, click the &quot;Add...&quot; button.
<p> <p>
To add a new property, enter a name, type and value for the new To add a new property, enter a name, type and value for the new
property and click the &quot;Add&quot; property and click the &quot;Add&quot;
button. button. For &quot;selection&quot; and &quot;multiple selection&quot;
properties enter the name of a selection variable in the &quot;Value&quot;
field. The selection variable is a property or method that returns a list
of strings from which the selection(s) can be chosen.
</p> </p>
<table> <table>
<tr> <tr>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment