#28213: New template filter like filesizeformat but for other units
-------------------------------------+-------------------------------------
               Reporter:  Nicolas    |          Owner:  nobody
  Bruot                              |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Template   |        Version:  1.11
  system                             |
               Severity:  Normal     |       Keywords:  Template filter
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 File sizes are not the only numbers with a unit that one may encounter
 when developing an app. **Would it make sense to add a more generic filter
 that acts on a number similarly to fileformatsize but for other units?**

 Rough idea of the behavior of the filter:
   - Takes a number as input (int, float, positive or negative)
   - Finds the most adapted 10^3n^ unit: m (10^-3^), nothing (1), k
 (10^3^), M (10^6^)...
   - Divides the number by 10^3n^ and localizes it
   - Append the unit

 The simplest way to do it may be for the filter to generate strings with
 just the power prefix like "123.4 k", "-20 m", and the rest of the unit
 can then be outside the tag, for example:
 {{{
 {% 123400|human %}m = 123.4 km (a length)
 {% 123400|human %}g = 123.4 kg (a mass)
 }}}

 However, this strategy makes it difficult for users to fix edge cases they
 may encounter. Instead, it might be worth to include the whole unit in the
 tag, in case the power prefix cannot be separated from the unit suffix (or
 when the suffix also depend on the power):
   - Suffix and prefix may not be separated in some languages (I don't
 know).
   - Happens for users that prefer full unit string for numbers < 1000, for
 example "123 km", but "123 meters" (the same way that filesizeformat uses
 "bytes" instead of "b" for a size below 1024).
 In such cases, we need to provide a way for the user to specify the unit
 strings for all the powers (or the other way around: the filter could spit
 out the power as well as the number, and the user can then work out from
 that whatever he wants to do).

--
Ticket URL: <https://code.djangoproject.com/ticket/28213>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.40ede357f07ee6a76c5b3ab9d44604bb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to