Module: check_mk
Branch: master
Commit: 7fcd499a8a095c572131ff94bbf7d14bcbe8d627
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7fcd499a8a095c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jan 25 10:39:59 2016 +0100
Datetime valuespec can now optinally handle empty input and result in None
---
web/htdocs/htmllib.py | 5 ++++-
web/htdocs/valuespec.py | 9 ++++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 15ed9b0..4ee35fa 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -529,8 +529,11 @@ class html(GUITester):
self.write(r'''onmouseover='this.style.backgroundImage="url(\"images/contextlink%s_hi.png\")";'
''' % what)
self.write(r'''onmouseout='this.style.backgroundImage="url(\"images/contextlink%s.png\")";'
''' % what)
+
def number_input(self, varname, deflt = "", size=8, style="",
submit=None):
- self.text_input(varname, str(deflt), "number", size=size, style=style,
submit=submit)
+ if deflt != None:
+ deflt = str(deflt)
+ self.text_input(varname, deflt, "number", size=size, style=style,
submit=submit)
# Needed if input elements are put into forms without the helper
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index c691b3c..3ffb467 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1935,7 +1935,7 @@ class RelativeDate(OptionalDropdownChoice):
# A ValueSpec for editing a date. The date is
# represented as a UNIX timestamp x where x % seconds_per_day
-# is zero (or will be ignored if non-zero), as long es
+# is zero (or will be ignored if non-zero), as long as
# include_time is not set to True
class AbsoluteDate(ValueSpec):
def __init__(self, **kwargs):
@@ -1946,6 +1946,11 @@ class AbsoluteDate(ValueSpec):
self._format = kwargs.get("format", self._include_time and "%F
%T" or "%F")
self._default_value = kwargs.get("default_value", None)
self._allow_empty = kwargs.get('allow_empty', False)
+ # The default is that "None" means show current date/time in the
+ # input fields. This option changes the input fields to be empty by default
+ # and makes the value able to be None when no time is set.
+ # FIXME: Shouldn't this be the default?
+ self._none_means_empty = kwargs.get("none_means_empty", False)
def default_value(self):
if self._default_value != None:
@@ -1963,6 +1968,8 @@ class AbsoluteDate(ValueSpec):
return self.default_value()
def split_date(self, value):
+ if self._none_means_empty and value == None:
+ return (None,) * 6
lt = time.localtime(value)
return lt.tm_year, lt.tm_mon, lt.tm_mday, \
lt.tm_hour, lt.tm_min, lt.tm_sec