Module: check_mk
Branch: master
Commit: eacb614142b8b8aa89d943a57707c937f4d0ba0d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eacb614142b8b8…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Oct 7 17:58:59 2014 +0200
Renamed several filter URI variables
These are variables that conflict with other filters. In most cases
these are pairs of regex and exact match filters. The regex filters
have been renamed in a way that there is no conflict anymore.
---
web/htdocs/views.py | 22 ++++++++++++++--------
web/htdocs/visuals.py | 29 ++++++++++++++++++++---------
web/plugins/visuals/filters.py | 12 ++++++------
3 files changed, 40 insertions(+), 23 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=eacb614142…
Module: check_mk
Branch: master
Commit: f5548c7a69f4a7fbb6c11cc4d8fa5e05de1c3b10
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f5548c7a69f4a7…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Oct 7 16:39:17 2014 +0200
Extract function for filters from view to visuals
---
web/htdocs/views.py | 20 ++------------------
web/htdocs/visuals.py | 34 ++++++++++++++++++++++++++++++----
2 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index eec6912..92e7f87 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -536,7 +536,6 @@ def transform_view_to_valuespec_value(view):
view['visibility'].append(key)
view['grouping'] = { "grouping" : view.get('group_painters', []) }
- view['filters'] = { "context" : view.get('context', {}) }
view['sorting'] = { "sorters" : view.get('sorters', {}) }
columns = []
@@ -559,8 +558,6 @@ def transform_view_to_valuespec_value(view):
columns.append((pname, viewname, ''))
-
-
def transform_valuespec_value_to_view(view):
for ident, attrs in view.items():
# Transform some valuespec specific options to legacy view
@@ -572,6 +569,7 @@ def transform_valuespec_value_to_view(view):
view[option] = True
del attrs['options']
view.update(attrs)
+ del view["view"]
elif ident == 'sorting':
view.update(attrs)
@@ -871,21 +869,7 @@ def show_view(view, show_heading = False, show_buttons = True,
# in context. In this case, take them from the context type definition.
show_filters = visuals.show_filters(view, datasource['infos'])
- # Populate the HTML vars with missing context vars. The context vars set
- # in single context are enforced (can not be overwritten by URL). The normal
- # filter vars in "multiple" context are not enforced.
- for key in visuals.get_single_info_keys(view):
- if key in view['context']:
- html.set_var(key, view['context'][key])
-
- # Now apply the multiple context filters
- for info_key in datasource['infos']:
- for fname, fval in view['context'].items():
- if type(fval) == dict: # this is a real filter
- for varname, val in fval.items():
- # shown filters are set, if form is fresh and variable not supplied in URL
- if only_count or (html.var("filled_in") != "filter" and not html.has_var(varname)):
- html.set_var(varname, val)
+ visuals.add_context_to_html_vars(view, datasource["infos"], only_count)
# Af any painter, sorter or filter needs the information about the host's
# inventory, then we load it and attach it as column "host_inventory"
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index d7c674e..8ff8d70 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -467,7 +467,6 @@ def process_context_specs(context_specs):
ident = 'context_' + info_key
attrs = spec.from_html_vars(ident)
- html.debug(attrs)
spec.validate_value(attrs, ident)
context.update(attrs)
return context
@@ -477,6 +476,9 @@ def render_context_specs(visual, context_specs):
for info_key, spec in context_specs:
forms.section(spec.title())
ident = 'context_' + info_key
+ # Trick: the field "context" contains a dictionary with
+ # all filter settings, from which the value spec will automatically
+ # extract those that it needs.
value = visual.get('context', {})
spec.render_input(ident, value)
@@ -623,8 +625,7 @@ def page_edit_visual(what, all_visuals, custom_field_handler = None,
save_and_go = None
for nr, (title, pagename, icon) in enumerate(sub_pages):
if html.var("save%d" % nr):
- save_and_go = html.makeuri_contextless([(visual_types[what]['ident_attr'], visualname)],
- filename = pagename + '.py')
+ save_and_go = pagename
if save_and_go or html.var("save") or html.var("try") or html.var("search"):
try:
@@ -656,7 +657,8 @@ def page_edit_visual(what, all_visuals, custom_field_handler = None,
if html.var("save") or save_and_go:
if save_and_go:
- back = save_and_go
+ back = html.makeuri_contextless([(visual_types[what]['ident_attr'], visual['name'])],
+ filename = save_and_go + '.py')
else:
back = html.var('back')
if not back:
@@ -869,6 +871,30 @@ def show_filters(visual, info_keys):
return list(set(show_filters)) # remove duplicates
+
+def add_context_to_html_vars(visual, only_infos=None, only_count=False):
+ if only_infos == None:
+ only_infos = infos.keys() # all datasources!
+
+ # Populate the HTML vars with missing context vars. The context vars set
+ # in single context are enforced (can not be overwritten by URL). The normal
+ # filter vars in "multiple" context are not enforced.
+ for key in get_single_info_keys(visual):
+ if key in visual['context']:
+ html.set_var(key, visual['context'][key])
+
+ # Now apply the multiple context filters
+ for info_key in only_infos:
+ for fname, fval in visual['context'].items():
+ if type(fval) == dict: # this is a real filter
+ for varname, val in fval.items():
+ # shown filters are set, if form is fresh and variable not supplied in URL
+ if only_count or (html.var("filled_in") != "filter" and not html.has_var(varname)):
+ html.set_var(varname, val)
+
+
+
+
#.
# .--ValueSpecs----------------------------------------------------------.
# | __ __ _ ____ |
Module: check_mk
Branch: master
Commit: 2b217065c944577b2b118b89b31770aa8ef586f2
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2b217065c94457…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Oct 7 13:20:23 2014 +0200
views: make transform function symmetric
---
web/htdocs/views.py | 116 +++++++++++++++++++++++++++++++++++----------------
1 file changed, 79 insertions(+), 37 deletions(-)
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 20cc908..eec6912 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -97,6 +97,9 @@ def transform_old_views():
ds_name = view['datasource']
datasource = multisite_datasources[ds_name]
+ if "context" not in view: # legacy views did not have this explicitly
+ view.setdefault("user_sortable", True)
+
# This tries to map the datasource and additional settings of the
# views to get the correct view context
if 'single_infos' not in view:
@@ -295,8 +298,8 @@ def page_edit_view():
visuals.page_edit_visual('views', multisite_views,
custom_field_handler = render_view_config,
- load_handler = transform_view_to_valuespec,
- create_handler = create_view_config,
+ load_handler = transform_view_to_valuespec_value,
+ create_handler = create_view_from_valuespec,
info_handler = get_view_infos,
try_handler = lambda view: show_view(view, False, False)
)
@@ -509,71 +512,74 @@ def render_view_config(view, general_properties=True):
view['datasource'] = ds_name
for ident, vs in view_editor_specs(ds_name, general_properties):
- vs.render_input(ident, view)
-
-# Is used to change the view structure to be compatible to the valuespec
-# This needs to perform the inverted steps of the create_view() function
-# FIXME: One day we should rewrite this to make no transform needed anymore
-def transform_view_to_valuespec(view):
- view['options'] = []
+ vs.render_input(ident, view[ident])
+
+# Is used to change the view structure to be compatible to
+# the valuespec This needs to perform the inverted steps of the
+# transform_valuespec_value_to_view() function. FIXME: One day we should
+# rewrite this to make no transform needed anymore
+def transform_view_to_valuespec_value(view):
+ view["view"] = {} # Several global variables are put into a sub-dict
+ # Only copy our known keys. Reporting element, etc. might have their own keys as well
+ for key in [ "datasource", "browser_reload", "layout", "num_columns", "column_headers" ]:
+ if key in view:
+ view["view"][key] = view[key]
+
+ view["view"]['options'] = []
for key, title in view_editor_options():
if view.get(key):
- view['options'].append(key)
+ view['view']['options'].append(key)
view['visibility'] = []
for key in [ 'hidden', 'hidebutton', 'public' ]:
if view.get(key):
view['visibility'].append(key)
- view['grouping'] = view['group_painters']
- view['filters'] = view['context']
+ view['grouping'] = { "grouping" : view.get('group_painters', []) }
+ view['filters'] = { "context" : view.get('context', {}) }
+ view['sorting'] = { "sorters" : view.get('sorters', {}) }
- view['columns'] = []
- for entry in view['painters']:
+ columns = []
+ view['columns'] = { "columns" : columns }
+ for entry in view.get('painters', []):
if len(entry) == 5:
pname, viewname, tooltip, join_index, col_title = entry
- view['columns'].append((pname, join_index, viewname, tooltip, col_title))
+ columns.append((pname, join_index, viewname, tooltip, col_title))
elif len(entry) == 4:
pname, viewname, tooltip, join_index = entry
- view['columns'].append((pname, join_index, viewname, tooltip, ''))
+ columns.append((pname, join_index, viewname, tooltip, ''))
elif len(entry) == 3:
pname, viewname, tooltip = entry
- view['columns'].append((pname, viewname, tooltip))
+ columns.append((pname, viewname, tooltip))
else:
pname, viewname = entry
- view['columns'].append((pname, viewname, ''))
+ columns.append((pname, viewname, ''))
+
-# Extract properties of view from HTML variables and construct
-# view object, to be used for saving or displaying
-#
-# old_view is the old view dict which might be loaded from storage.
-# view is the new dict object to be updated.
-def create_view_config(old_view, view):
- ds_name = old_view.get('datasource', html.var('datasource'))
- datasource = multisite_datasources[ds_name]
- for ident, vs in view_editor_specs(ds_name):
- attrs = vs.from_html_vars(ident)
- vs.validate_value(attrs, ident)
+def transform_valuespec_value_to_view(view):
+ for ident, attrs in view.items():
# Transform some valuespec specific options to legacy view
# format. We do not want to change the view data structure
# at the moment.
if ident == 'view':
- for option in attrs['options']:
- view[option] = True
- del attrs['options']
-
+ if "options" in attrs:
+ for option in attrs['options']:
+ view[option] = True
+ del attrs['options']
view.update(attrs)
elif ident == 'sorting':
view.update(attrs)
+ del view["sorting"]
elif ident == 'grouping':
view['group_painters'] = attrs['grouping']
+ del view["grouping"]
elif ident == 'columns':
painters = []
@@ -593,7 +599,25 @@ def create_view_config(old_view, view):
else:
painters.append((pname, viewname, tooltip))
view['painters'] = painters
+ del view["columns"]
+
+# Extract properties of view from HTML variables and construct
+# view object, to be used for saving or displaying
+#
+# old_view is the old view dict which might be loaded from storage.
+# view is the new dict object to be updated.
+def create_view_from_valuespec(old_view, view):
+ ds_name = old_view.get('datasource', html.var('datasource'))
+ datasource = multisite_datasources[ds_name]
+ vs_value = {}
+ for ident, vs in view_editor_specs(ds_name):
+ attrs = vs.from_html_vars(ident)
+ vs.validate_value(attrs, ident)
+ vs_value[ident] = attrs
+
+ transform_valuespec_value_to_view(vs_value)
+ view.update(vs_value)
return view
#.
@@ -704,6 +728,13 @@ def page_view():
# (e.g. from the services table while we are in a hosts view)
# If join_columns is False, we only return the "normal" columns.
def get_needed_columns(view, painters):
+ # Make sure that the information about the available views is present. If
+ # called via the reporting, than this might not be the case
+ try:
+ available_views
+ except:
+ load_views()
+
columns = []
for entry in painters:
painter = entry[0]
@@ -818,8 +849,13 @@ def show_view(view, show_heading = False, show_buttons = True,
display_options = prepare_display_options()
# User can override the layout settings via HTML variables (buttons)
- # which are safed persistently. This is known as "view options"
- vo = view_options(view["name"])
+ # which are safed persistently. This is known as "view options". Note: a few
+ # can be anonymous (e.g. when embedded into a report). In that case there
+ # are no display options.
+ if "name" in view:
+ vo = view_options(view["name"])
+ else:
+ vo = {}
num_columns = vo.get("num_columns", view.get("num_columns", 1))
browser_reload = vo.get("refresh", view.get("browser_reload", None))
@@ -994,9 +1030,15 @@ def show_view(view, show_heading = False, show_buttons = True,
html.set_browser_reload(browser_reload)
# The layout of the view: it can be overridden by several specifying
- # an output format (like json or python).
+ # an output format (like json or python). Note: the layout is not
+ # always needed. In case of an embedded view in the reporting this
+ # field is simply missing, because the rendering is done by the
+ # report itself.
if html.output_format == "html":
- layout = multisite_layouts[view["layout"]]
+ if "layout" in view:
+ layout = multisite_layouts[view["layout"]]
+ else:
+ layout = None
else:
layout = multisite_layouts.get(html.output_format)
if not layout: