Opened 15 years ago
Closed 13 years ago
#11166 closed Bug (fixed)
{% widthratio 0 0 100 %} returns an empty string, rather than a 0
Reported by: | Ludwig Pettersson | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When supplying the {% widthratio %} template tag with both a value and max of 0 - you get an empty string returned (), rather than a 0. Mathematically, this is correct - since typically division by zero results in undefined, but I wouldn't say this is the expected behaviour when using this to create charts, where a 0 rather than nothing, would be expected.
Example:
<img width="{% widthratio 0 0 100 %}" height="10" ... /> <img style="width:{% widthratio 0 0 100 %}px; height:10px" ... />
This would produce:
<img width="" height="10" ... /> <img style="width:px; height:10px" ... />
Now, in the first example, the difference is only semantic - but the second one creates invalid css as well, not such a big of a deal, but, gets troublesome when you *need* a number returned, such as when using {% widthratio %} with the google charts api. (sparklines, for example, require a number between 0-100 - anything above 100, such as 550, is visually returned as 100 in the chart - so you can't have empty values.)
But, when would anyone ever encounter this problem? I personally do when displaying data over a time period, where in some cases, nothing may have happened - leaving everything at 0, both the values and max values - which then results in everything showing up empty, rather than defaulting back to 0.
I realize this is easy to work around, but I thought I would put it out there since at least I wasn't expecting this behavior and it seems a bit weird, especially when this is mainly used to create charts in templates.
(Patch is for the latest svn checkout as of this writing, rev 10833)
Attachments (1)
Change History (6)
by , 15 years ago
Attachment: | django-diff.txt added |
---|
comment:1 by , 15 years ago
Component: | Uncategorized → Template system |
---|---|
Has patch: | set |
Version: | 1.0 → SVN |
comment:2 by , 15 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:4 by , 13 years ago
Easy pickings: | unset |
---|---|
Triage Stage: | Design decision needed → Accepted |
UI/UX: | unset |
I agree that the empty string is technically the "correct" output (the template engine returns nothing whenever an exception occurs), but that in this case "practicality beats purity".
svn diff of patch