Skip to content

Commit

Permalink
Factored out format_size method for replacing getObjSize.py. #1801
Browse files Browse the repository at this point in the history
  • Loading branch information
reinhardt committed Oct 1, 2018
1 parent c7c3243 commit 072dba9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Breaking changes:

New features:

- Factored out format_size method for replacing getObjSize.py. #1801
[reinhardt]

- Update TinyMCE to 4.7.13
[erral]

Expand Down
23 changes: 14 additions & 9 deletions Products/CMFPlone/CatalogTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,10 @@ def getObjPositionInParent(obj):
SIZE_ORDER = ('GB', 'MB', 'KB')


@indexer(Interface)
def getObjSize(obj):
""" Helper method for catalog based folder contents.
"""
def format_size(size):
""" Get a human readable size string. """
smaller = SIZE_ORDER[-1]

if base_hasattr(obj, 'get_size'):
size = obj.get_size()
else:
size = 0

# if the size is a float, then make it an int
# happens for large files
try:
Expand All @@ -250,6 +243,18 @@ def getObjSize(obj):
return size


@indexer(Interface)
def getObjSize(obj):
""" Helper method for catalog based folder contents.
"""
if base_hasattr(obj, 'get_size'):
size = obj.get_size()
else:
size = 0

return format_size(size)


@indexer(Interface)
def is_folderish(obj):
"""Should this item be treated as a folder?
Expand Down

0 comments on commit 072dba9

Please sign in to comment.