Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

filesizeformat dont work properly. #59

Closed
wants to merge 1 commit into from

7 participants

@aW4KeNiNG

Wrong results:
Example:
value 300000 (bytes) --> result 0.3 kB --> expected 300.0 kB
value 3000000 --> result 0.0 MB --> expected 3.0 MB

@aW4KeNiNG aW4KeNiNG filesizeformat dont work properly.
Wrong results: 
Example:
value 300000 (bytes) --> result 0.3 kB --> expected 300.0 kB
value 3000000 --> result 0.0 MB --> expected 3.0 MB
95b1d60
@EnTeQuAk

Actually the unittest itself is wrong, I compared the implementation with the Django one and found that the binary calculation was indeed wrong. This was what I came up with: http://paste.pocoo.org/show/489117/

This actually is a mix with #53

@mitsuhiko - would like to get some feedback :)

@EnTeQuAk

And actually pushed it to my own fork ;)

@mitsuhiko mitsuhiko closed this in 7d268be
@jmafc jmafc referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@lgautier

Is there a bugfix release to Jinga2 planned ? Fixes such as this one would be neat to have in a released version.

@mcilrain

Why is this still broken?

@quasipedia

Indeed. Jinja 2.6 still fails at this:

{{ extra.feed_size | filesizeformat }} [{{ '%d' | format(extra.feed_size) }} bytes]

results in:

0.0 kB [28227 bytes]
@soulseekah

It's been fixed in 7d268be but there hasn't been any maintenance release for Jinja 2 that included the fix; there hasn't been any sort of release - the tarball at http://pypi.python.org/pypi/Jinja2 is more than 14 months old. Only solution for now is to patch the function manually (to avoid running unstable master branches).

@wrayan wrayan referenced this pull request from a commit in wrayan/maraschino
@wrayan wrayan jinja2: fix broken filesizeformat filter 49c26bb
@aimanparvaiz aimanparvaiz referenced this pull request in Jahaja/psdash
Closed

Memory and disk usage show 0 #9

@Jahaja Jahaja referenced this pull request from a commit in Jahaja/psdash
@Jahaja Jahaja Fixed issue where file size formatted values would be displayed as zero.
This was caused by an bug present in Jinja:
mitsuhiko/jinja2#59
1258759
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 20, 2011
  1. @aW4KeNiNG

    filesizeformat dont work properly.

    aW4KeNiNG authored
    Wrong results: 
    Example:
    value 300000 (bytes) --> result 0.3 kB --> expected 300.0 kB
    value 3000000 --> result 0.0 MB --> expected 3.0 MB
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2 jinja2/filters.py
View
4 jinja2/filters.py
@@ -361,8 +361,8 @@ def do_filesizeformat(value, binary=False):
return "%d Bytes" % bytes
else:
for i, prefix in enumerate(prefixes):
- unit = base * base ** (i + 1)
- if bytes < unit:
+ unit = base ** (i + 1)
+ if bytes < unit*base:
return "%.1f %s" % ((bytes / unit), prefix)
return "%.1f %s" % ((bytes / unit), prefix)
Something went wrong with that request. Please try again.