Module: check_mk
Branch: master
Commit: 74b66535d404d86154e2427614ab6987d0f969d4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=74b66535d404d8…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Jan 9 15:19:04 2012 +0100
ValueSpec Integer: thousand separator
---
web/htdocs/valuespec.py | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index cbefb10..aab449a 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -167,11 +167,13 @@ class Age(ValueSpec):
class Integer(ValueSpec):
def __init__(self, **kwargs):
ValueSpec.__init__(self, **kwargs)
- self._size = kwargs.get("size", 5)
- self._minvalue = kwargs.get("minvalue")
- self._maxvalue = kwargs.get("maxvalue")
- self._label = kwargs.get("label")
- self._unit = kwargs.get("unit", "")
+ self._size = kwargs.get("size", 5)
+ self._minvalue = kwargs.get("minvalue")
+ self._maxvalue = kwargs.get("maxvalue")
+ self._label = kwargs.get("label")
+ self._unit = kwargs.get("unit", "")
+ self._thousand_sep = kwargs.get("thousand_sep")
+
if "size" not in kwargs and "maxvalue" in kwargs:
self._size = 1 + int(math.log10(self._maxvalue))
@@ -199,6 +201,15 @@ class Integer(ValueSpec):
def value_to_text(self, value):
text = str(value)
+ if self._thousand_sep:
+ sepped = ""
+ rest = text
+ while len(rest) > 3:
+ sepped = self._thousand_sep + rest[-3:] + sepped
+ rest = rest[:-3]
+ sepped = rest + sepped
+ text = sepped
+
if self._unit:
text += " " + self._unit
return text