Module: check_mk
Branch: master
Commit: 06817e9f7c254cf1522d0f5ba52b48573536cf76
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=06817e9f7c254c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Dec 23 10:53:19 2016 +0100
htmllib: New generic helper for processing integers from request vars:
get_integer_input()
Change-Id: I320a89767697f6fe45ad70cf134d064208d5919e
---
web/htdocs/htmllib.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 423d334..39911b2 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1458,6 +1458,14 @@ class html(DeprecationWrapper):
raise MKUserError(varname, _("The given text is wrong encoded. "
"You need to provide a UTF-8 encoded
text."))
+ def get_integer_input(self, varname):
+ try:
+ return int(self.var(varname))
+ except TypeError:
+ raise MKUserError(varname, _("The parameter \"%s\" is
missing.") % varname)
+ except ValueError:
+ raise MKUserError(varname, _("The parameter \"%s\" is not an
integer.") % varname)
+
def var(self, varname, deflt = None):
return self.vars.get(varname, deflt)