Module: check_mk
Branch: master
Commit: 5a52add8771c9b1c48e3055f1e1c048a5b631db9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5a52add8771c9b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Oct 29 17:27:17 2011 +0200
WATO: make parsing of time periods more conveniant
---
web/htdocs/wato.py | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 7b6f936..afac92e 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -5082,16 +5082,27 @@ def mode_edit_timeperiod(phase):
begin = "00:00"
if not end:
end = "24:00"
- for what, bound in [ ("from", begin), ("to", end) ]:
- if not valid_bound(bound):
- raise MKUserError(vp + what,
- _("Invalid time format '<tt>%s</tt>',
please use <tt>24:00</tt> format.") % bound)
+
+ begin, end = [ parse_bound(w, b) for (w,b) in [ ("from", begin),
("to", end) ]]
ranges.append((begin, end))
return ranges
- def valid_bound(bound):
- return re.match("^(24|[0-1][0-9]|2[0-3]):[0-5][0-9]$", bound)
+ def parse_bound(what, bound):
+ # Fully specified
+ if re.match("^(24|[0-1][0-9]|2[0-3]):[0-5][0-9]$", bound):
+ return bound
+ # only hours
+ try:
+ b = int(bound)
+ if b <= 24 and b >= 0:
+ return "%02d:00" % b
+ except:
+ pass
+
+ raise MKUserError(vp + what,
+ _("Invalid time format '<tt>%s</tt>', please use
<tt>24:00</tt> format.") % bound)
+
name = html.var("edit") # missing -> new group
new = name == None