Roundup Tracker - Issues

Issue 2550559

classification
Pretty printing / formatting for Number types.
Type: rfe Severity: normal
Components: Web interface Versions:
process
Status: fixed fixed
:
: rouilj : ber, chichi, rouilj
Priority: normal : Effort-Low

Created on 2009-07-08 10:44 by ber, last changed 2022-08-23 13:30 by rouilj.

Messages
msg3750 Author: [hidden] (ber) Date: 2009-07-08 10:44
It would be nice to have a way to pretty print "Number"s.

It probably would be implemented in
roundup/cgi/templating.py class NumberHTMLProperty()
like
    def pretty(self, format=_default)
similiar to the one for Date.

The use case is for attribues that are used as Integers
e.g. not displaying "90.0" and for numbers that are better shown
with spaces in front like amounts.
It could all be done with regular % python formatting.
Currently it cannot be done directly easily,
because the value can also be None, so __float__() from class Number
does not always work.
msg4095 Author: [hidden] (chichi) Date: 2010-07-16 08:22
Anybody has any idea about this?

Thanks!
msg4097 Author: [hidden] (ber) Date: 2010-07-20 09:12
Well it just needs to be implemented.
msg4099 Author: [hidden] (chichi) Date: 2010-07-22 08:24
Yap...:p
msg7635 Author: [hidden] (rouilj) Date: 2022-08-17 02:40
Bern:

I implemented pretty(self, format="%0.3f").

One thing I didn't expect is that "%0.3f"%True is 1.000.

What should pretty return if the value is None, or can't be represented using the specified 
format parameter? 

I implemented "" for None and str(self._value) for anything else.

Does that work?

If the format is invalid (e.g. '%0.3') it raises a ValueError and that should
get handled like any other error.

changeset:   6832:234fefd7568a
msg7639 Author: [hidden] (ber) Date: 2022-08-23 07:18
Hi John,
the original idea was about formatting numbers,
not about boolean or other types.

I think the behavior you have described is good.

Thanks for implementing!
Bernhard
History
Date User Action Args
2022-08-23 13:30:24rouiljsetstatus: open -> fixed
resolution: remind -> fixed
2022-08-23 07:18:45bersetmessages: + msg7639
2022-08-17 02:41:21rouiljsetstatus: pending -> open
2022-08-17 02:40:07rouiljsetstatus: new -> pending
assignee: rouilj
resolution: remind
messages: + msg7635
nosy: + rouilj
2016-07-04 19:57:09rouiljsetfiles: - unnamed
2016-07-04 19:39:45rouiljsetkeywords: + Effort-Low
2010-07-22 08:24:54chichisetfiles: + unnamed
messages: + msg4099
2010-07-20 09:12:12bersetmessages: + msg4097
2010-07-16 08:22:22chichisetmessages: + msg4095
2010-03-08 06:04:23chichisetnosy: + chichi
2009-07-08 10:44:18bercreate