Module: check_mk
Branch: master
Commit: a19ee834e80d2885ce3e847f620a31833cdda1d8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a19ee834e80d28…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Apr 5 11:16:52 2017 +0200
CME: Implemented sidebar logo upload
Change-Id: I03aa3322a23a420c8a3051e4cd48e0ed26219266
---
web/htdocs/valuespec.py | 32 ++++++++++++++++++++++++++++++++
web/htdocs/wato.py | 24 ++++++------------------
2 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index e775d92..631b655 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -3947,6 +3947,38 @@ class FileUpload(ValueSpec):
+class ImageUpload(FileUpload):
+ def __init__(self, max_size=None, *args, **kwargs):
+ self._max_size = max_size
+ FileUpload.__init__(self, *args, **kwargs)
+
+
+ def validate_value(self, value, varprefix):
+ from PIL import Image
+ from StringIO import StringIO
+
+ file_name, mime_type, content = value
+
+ if file_name[-4:] != '.png' \
+ or mime_type != 'image/png' \
+ or not content.startswith('\x89PNG'):
+ raise MKUserError(varprefix, _('Please choose a PNG image.'))
+
+ try:
+ im = Image.open(StringIO(content))
+ except IOError:
+ raise MKUserError(varprefix, _('Please choose a valid PNG image.'))
+
+ if self._max_size:
+ w, h = im.size
+ max_w, max_h = self._max_size
+ if w > max_w or h > max_h:
+ raise MKUserError(varprefix, _('Maximum image size: %dx%dpx') %
(max_w, max_h))
+
+ ValueSpec.custom_validate(self, value, varprefix)
+
+
+
class UploadOrPasteTextFile(Alternative):
def __init__(self, **kwargs):
file_title = kwargs.get("file_title", _("File"))
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index c77d41b..c58215d 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -6616,6 +6616,10 @@ def mode_globalvars(phase):
if config.user.may("wato.set_read_only"):
html.context_button(_("Read only mode"),
folder_preserving_link([("mode", "read_only")]),
"read_only")
+
+ if cmk.is_managed_edition():
+ cme_global_settings_buttons()
+
return
# Get default settings of all configuration variables of interest in the domain
@@ -15555,23 +15559,6 @@ def manpage_text(text):
# '----------------------------------------------------------------------'
def validate_icon(value, varprefix):
- from PIL import Image
- from StringIO import StringIO
- file_name, mime_type, content = value
- if file_name[-4:] != '.png' \
- or mime_type != 'image/png' \
- or not content.startswith('\x89PNG'):
- raise MKUserError(varprefix, _('Please choose a PNG icon.'))
-
- try:
- im = Image.open(StringIO(content))
- except IOError:
- raise MKUserError(varprefix, _('Please choose a valid PNG icon.'))
-
- w, h = im.size
- if w > 80 or h > 80:
- raise MKUserError(varprefix, _('Maximum image size: 80x80px'))
-
if os.path.exists("%s/share/check_mk/web/htdocs/images/icon_%s" %
(cmk.paths.omd_root, file_name)) \
or os.path.exists("%s/share/check_mk/web/htdocs/images/icons/%s" %
(cmk.paths.omd_root, file_name)):
raise MKUserError(varprefix, _('Your icon conflicts with a Check_MK builtin
icon. Please '
@@ -15622,9 +15609,10 @@ def mode_icons(phase):
optional_keys = False,
render = "form",
elements = [
- ('icon', FileUpload(
+ ('icon', ImageUpload(
title = _('Icon'),
allow_empty = False,
+ max_size = (80, 80),
validate = validate_icon,
)),
('category', DropdownChoice(