[Zope-Checkins] SVN: Zope/trunk/lib/python/OFS/ Launchpad #142350: Display description for properties as row title, if present.

Tres Seaver tseaver at palladion.com
Mon May 5 11:28:29 EDT 2008


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

Changed:
  U   Zope/trunk/lib/python/OFS/PropertyManager.py
  U   Zope/trunk/lib/python/OFS/dtml/properties.dtml
  U   Zope/trunk/lib/python/OFS/tests/testProperties.py

-=-
Modified: Zope/trunk/lib/python/OFS/PropertyManager.py
===================================================================
--- Zope/trunk/lib/python/OFS/PropertyManager.py	2008-05-05 15:25:30 UTC (rev 86456)
+++ Zope/trunk/lib/python/OFS/PropertyManager.py	2008-05-05 15:28:29 UTC (rev 86457)
@@ -258,6 +258,16 @@
                 return p.get('label', id)
         return id
 
+    security.declareProtected(access_contents_information,
+                              'propertyDescription')
+    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
+
     security.declareProtected(access_contents_information, 'propdict')
     def propdict(self):
         dict={}

Modified: Zope/trunk/lib/python/OFS/dtml/properties.dtml
===================================================================
--- Zope/trunk/lib/python/OFS/dtml/properties.dtml	2008-05-05 15:25:30 UTC (rev 86456)
+++ Zope/trunk/lib/python/OFS/dtml/properties.dtml	2008-05-05 15:28:29 UTC (rev 86457)
@@ -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/trunk/lib/python/OFS/tests/testProperties.py
===================================================================
--- Zope/trunk/lib/python/OFS/tests/testProperties.py	2008-05-05 15:25:30 UTC (rev 86456)
+++ Zope/trunk/lib/python/OFS/tests/testProperties.py	2008-05-05 15:28:29 UTC (rev 86457)
@@ -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