[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/applicationcontrol/browser/ merge r37393 from the trunk:

Philipp von Weitershausen philikon at philikon.de
Sat Jul 23 12:02:54 EDT 2005


Log message for revision 37394:
  merge r37393 from the trunk:
    support storages that can't report their size
    reuse zope.app.size.byteDisplay for displaying a size in bytes
    as a localized string.
  

Changed:
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/applicationcontrol/browser/ftests/test_zodbcontrol.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/applicationcontrol/browser/zodbcontrol.py

-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/applicationcontrol/browser/ftests/test_zodbcontrol.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/applicationcontrol/browser/ftests/test_zodbcontrol.py	2005-07-23 15:43:27 UTC (rev 37393)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/applicationcontrol/browser/ftests/test_zodbcontrol.py	2005-07-23 16:02:53 UTC (rev 37394)
@@ -28,10 +28,9 @@
                                 form={'days': u'3'})
         body = response.getBody()
         self.assert_('value="3"' in body)
-        self.assert_('<em>Demo Storage</em>' in body)
-        self.assert_('<em>100 Bytes</em>' in body)
+        self.assert_('>Demo Storage</' in body)
+        self.assert_('>1 KB</' in body)
 
-
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(ZODBControlTest))

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/applicationcontrol/browser/zodbcontrol.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/applicationcontrol/browser/zodbcontrol.py	2005-07-23 15:43:27 UTC (rev 37393)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/applicationcontrol/browser/zodbcontrol.py	2005-07-23 16:02:53 UTC (rev 37394)
@@ -19,6 +19,7 @@
 
 from ZODB.FileStorage.FileStorage import FileStorageError
 from zope.app.i18n import ZopeMessageIDFactory as _
+from zope.app.size import byteDisplay
 
 class ZODBControlView(object):
 
@@ -29,19 +30,10 @@
     def getSize(self):
         """Get the database size in a human readable format."""
         size = self.request.publication.db.getSize()
-        if size > 1024**2:
-            size_str = _("${size} MB")
-            size_str.mapping = {'size': "%.1f" %(float(size)/1024**2)}
-        elif size > 1024:
-            size_str = _("${size} kB")
-            size_str.mapping = {'size': "%.1f" %(float(size)/1024)}
-        else:
-            size_str = _("${size} Bytes")
-            size_str.mapping = {'size': "%i" %size}
+        if not isinstance(size, (int, long, float)):
+            return str(size)
+        return byteDisplay(size)        
 
-        return size_str
-        
-
     def pack(self):
         """Do the packing!"""
         days = int(self.request.form.get('days', 0))



More information about the Zope3-Checkins mailing list