Skip to content

Commit

Permalink
merge r37393 from the trunk:
Browse files Browse the repository at this point in the history
  support storages that can't report their size
  reuse zope.app.size.byteDisplay for displaying a size in bytes
  as a localized string.
  • Loading branch information
philikon committed Jul 23, 2005
1 parent d65ea14 commit 4e86daf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
5 changes: 2 additions & 3 deletions browser/ftests/test_zodbcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ def testZODBControlOverview(self):
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()
Expand Down
16 changes: 4 additions & 12 deletions browser/zodbcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -29,18 +30,9 @@ def getName(self):
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}

return size_str

if not isinstance(size, (int, long, float)):
return str(size)
return byteDisplay(size)

def pack(self):
"""Do the packing!"""
Expand Down

0 comments on commit 4e86daf

Please sign in to comment.