Module: check_mk
Branch: master
Commit: 648922f00d41ae663572af5f38fd37b11721ad1f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=648922f00d41ae…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 16 17:04:39 2018 +0100
Moved date specific human rendering methods to more specific places and more often use
cmk.render
Change-Id: Icab44fdfb7c6c9e75e8b9d0458cf3095256ec7bc
---
cmk/render.py | 6 +++---
web/htdocs/key_mgmt.py | 3 ++-
web/htdocs/lib.py | 37 -------------------------------------
web/htdocs/notifications.py | 3 ++-
4 files changed, 7 insertions(+), 42 deletions(-)
diff --git a/cmk/render.py b/cmk/render.py
index 29d7df8..b470398 100644
--- a/cmk/render.py
+++ b/cmk/render.py
@@ -43,15 +43,15 @@ except NameError:
def date(timestamp):
- return time.strftime("%Y-%m-%d", time.localtime(timestamp))
+ return time.strftime(_("%Y-%m-%d"), time.localtime(timestamp))
def date_and_time(timestamp):
- return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))
+ return time.strftime(_("%Y-%m-%d %H:%M:%S"), time.localtime(timestamp))
def time_of_day(timestamp):
- return time.strftime("%H:%M:%S", time.localtime(timestamp))
+ return time.strftime(_("%H:%M:%S"), time.localtime(timestamp))
def timespan(seconds):
diff --git a/web/htdocs/key_mgmt.py b/web/htdocs/key_mgmt.py
index be3ab60..d233225 100644
--- a/web/htdocs/key_mgmt.py
+++ b/web/htdocs/key_mgmt.py
@@ -33,6 +33,7 @@ os.environ["CRYPTOGRAPHY_ALLOW_OPENSSL_098"] = "1"
from OpenSSL import crypto
+import cmk.render
import cmk.store as store
import table
@@ -176,7 +177,7 @@ class PageKeyManagement(object):
("mode", self.download_mode),
("key", key_id)])
html.icon_button(download_url, _("Download this key"),
"download")
table.cell(_("Description"),
html.render_text(key["alias"]))
- table.cell(_("Created"),
date_human_readable(key["date"]))
+ table.cell(_("Created"), cmk.render.date(key["date"]))
table.cell(_("By"), html.render_text(key["owner"]))
table.cell(_("Digest (MD5)"),
html.render_text(cert.digest("md5")))
table.end()
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 5f4562d..438ae65 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -427,40 +427,3 @@ def age_human_readable(secs, min_only=False):
return "%.1f %s" % (years, _("y"))
else:
return "%.0f %s" % (years, _("y"))
-
-
-def date_human_readable(timestamp):
- # This can be localized:
- return time.strftime(_("%m/%d/%Y"), time.localtime(timestamp))
-
-def datetime_human_readable(timestamp):
- # This can be localized:
- return time.strftime(_("%m/%d/%Y %H:%M:%S"), time.localtime(timestamp))
-
-def date_range_human_readable(start_time, end_time):
- start_time_local = time.localtime(start_time)
- end_time_local = time.localtime(end_time)
- if start_time_local[:3] == end_time_local[:3]: # same day
- return date_human_readable(start_time)
-
- elif start_time_local[:2] == end_time_local[:2]: # same month
- date_format = _("%m/%d1-%d2/%Y")
- f = date_format.replace("%d2", time.strftime("%d",
end_time_local))
- f = f.replace("%d1", "%d")
- return time.strftime(f, start_time_local)
-
- elif start_time_local[0] == end_time_local[0]: # same year
- date_format = _("%m1/%d1/%Y - %m2/%d2/%Y")
- f = date_format.replace("%d2", time.strftime("%d",
end_time_local))
- f = f.replace("%m2", time.strftime("%m", end_time_local))
- f = f.replace("%d1", "%d").replace("%m1",
"%m")
- return time.strftime(f, start_time_local)
-
- else:
- return date_human_readable(start_time) + " - " + \
- date_human_readable(end_time)
-
-# Just print year and month, no day
-def date_month_human_readable(timestamp):
- # TODO: %B will currently not be localized
- return time.strftime(_("%B %Y"), time.localtime(timestamp))
diff --git a/web/htdocs/notifications.py b/web/htdocs/notifications.py
index efd47c6..32b0032 100644
--- a/web/htdocs/notifications.py
+++ b/web/htdocs/notifications.py
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+import cmk.render
import config
import lib
import sites
@@ -170,7 +171,7 @@ def render_page_confirm(acktime, prev_url, failed_notifications):
if failed_notifications:
html.write('<div class="really">\n')
html.write(_("Do you really want to acknowledge all failed notifications up
to %s?") %\
- lib.datetime_human_readable(acktime))
+ cmk.render.date_and_time(acktime))
html.begin_form("confirm", method="GET", action=prev_url)
html.hidden_field('acktime', acktime),
html.button('_confirm', _("Yes"))