[Zope-Checkins] SVN: Zope/branches/2.9/ Launchpad #142350: Display description for properties as row title, if present.

Tres Seaver tseaver at palladion.com
Mon May 5 11:14:54 EDT 2008


Log message for revision 86454:
  Launchpad #142350: Display description for properties as row title, if present.
  
  

Changed:
  U   Zope/branches/2.9/doc/CHANGES.txt
  U   Zope/branches/2.9/lib/python/OFS/PropertyManager.py
  U   Zope/branches/2.9/lib/python/OFS/dtml/properties.dtml
  U   Zope/branches/2.9/lib/python/OFS/tests/testProperties.py

-=-
Modified: Zope/branches/2.9/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.9/doc/CHANGES.txt	2008-05-05 13:46:05 UTC (rev 86453)
+++ Zope/branches/2.9/doc/CHANGES.txt	2008-05-05 15:14:52 UTC (rev 86454)
@@ -8,6 +8,9 @@
 
    Bugs fixed
 
+      - Launchpad #142350: Display description for properties as row title,
+        if present.
+
       - Launchpad #200007: DateTime(anotherDateTime) now preserves the
         timezone.
 

Modified: Zope/branches/2.9/lib/python/OFS/PropertyManager.py
===================================================================
--- Zope/branches/2.9/lib/python/OFS/PropertyManager.py	2008-05-05 13:46:05 UTC (rev 86453)
+++ Zope/branches/2.9/lib/python/OFS/PropertyManager.py	2008-05-05 15:14:52 UTC (rev 86454)
@@ -122,7 +122,7 @@
         ('Access contents information',
          ('hasProperty', 'propertyIds', 'propertyValues','propertyItems',
           'getProperty', 'getPropertyType', 'propertyMap', 'propertyLabel',
-          'propdict', 'valid_property_id', ''),
+          'propertyDescription', 'propdict', 'valid_property_id', ''),
          ('Anonymous', 'Manager'),
          ),
         )
@@ -256,6 +256,14 @@
                 return p.get('label', id)
         return id
 
+    def propertyDescription(self, id):
+        """Return a description for the given property id
+        """
+        for p in self._properties:
+            if p['id'] == id:
+                return p.get('description', '')
+        return id
+
     def propdict(self):
         dict={}
         for p in self._properties:

Modified: Zope/branches/2.9/lib/python/OFS/dtml/properties.dtml
===================================================================
--- Zope/branches/2.9/lib/python/OFS/dtml/properties.dtml	2008-05-05 13:46:05 UTC (rev 86453)
+++ Zope/branches/2.9/lib/python/OFS/dtml/properties.dtml	2008-05-05 15:14:52 UTC (rev 86454)
@@ -61,8 +61,9 @@
 </tr>
 
 <dtml-in propertyMap mapping>
-<dtml-let type="not _.has_key('type') and 'string' or type">
-<tr>
+<dtml-let type="not _.has_key('type') and 'string' or type"
+          pdesc="propertyDescription(id)">
+<tr title="&dtml-pdesc;">
   <td align="left" valign="top" width="16">
   <dtml-if "'d' in _['sequence-item'].get('mode', 'awd')">
   <input type="checkbox" name="_ids:<dtml-var "REQUEST['management_page_charset_tag']">string:list" value="&dtml-id;"

Modified: Zope/branches/2.9/lib/python/OFS/tests/testProperties.py
===================================================================
--- Zope/branches/2.9/lib/python/OFS/tests/testProperties.py	2008-05-05 13:46:05 UTC (rev 86453)
+++ Zope/branches/2.9/lib/python/OFS/tests/testProperties.py	2008-05-05 15:14:52 UTC (rev 86454)
@@ -21,10 +21,12 @@
 class TestPropertyManager(unittest.TestCase):
     """Property management tests."""
 
-    def _makeOne(self, *args, **kw):
+    def _getTargetClass(self):
         from OFS.PropertyManager import PropertyManager
+        return PropertyManager
 
-        return PropertyManager(*args, **kw)
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
 
     def test_z3interfaces(self):
         from OFS.interfaces import IPropertyManager
@@ -52,7 +54,41 @@
         self.failUnless(type(inst.getProperty('prop2')) == type(()))
         self.failUnless(type(inst.prop2) == type(()))
 
+    def test_propertyLabel_no_label_falls_back_to_id(self):
+        class NoLabel(self._getTargetClass()):
+            _properties = (
+                {'id': 'no_label', 'type': 'string'},
+            )
+        inst = NoLabel()
+        self.assertEqual(inst.propertyLabel('no_label'), 'no_label')
 
+    def test_propertyLabel_with_label(self):
+        class WithLabel(self._getTargetClass()):
+            _properties = (
+                {'id': 'with_label', 'type': 'string', 'label': 'With Label'},
+            )
+        inst = WithLabel()
+        self.assertEqual(inst.propertyLabel('with_label'), 'With Label')
+
+    def test_propertyDescription_no_description_falls_back_to_id(self):
+        class NoDescription(self._getTargetClass()):
+            _properties = (
+                {'id': 'no_description', 'type': 'string'},
+            )
+        inst = NoDescription()
+        self.assertEqual(inst.propertyDescription('no_description'), '')
+
+    def test_propertyDescription_with_description(self):
+        class WithDescription(self._getTargetClass()):
+            _properties = (
+                {'id': 'with_description', 'type': 'string',
+                 'description': 'With Description'},
+            )
+        inst = WithDescription()
+        self.assertEqual(inst.propertyDescription('with_description'),
+                         'With Description')
+
+
 class TestPropertySheet(unittest.TestCase):
     """Property management tests."""
 



More information about the Zope-Checkins mailing list