Module: check_mk
Branch: master
Commit: e98e41b853bb128b41a8c5fe49cf293d56d0cf4d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e98e41b853bb12…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 4 14:38:37 2019 +0100
Propagate View objects to Cell instances instead of the view spec
Change-Id: I7dc67c27220386af928b193d12a98ed030497461
---
cmk/gui/plugins/views/utils.py | 20 ++++++++++----------
cmk/gui/views.py | 8 ++++----
tests/unit/cmk/gui/test_views.py | 6 +++---
3 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/cmk/gui/plugins/views/utils.py b/cmk/gui/plugins/views/utils.py
index 82285a6..6a006b1 100644
--- a/cmk/gui/plugins/views/utils.py
+++ b/cmk/gui/plugins/views/utils.py
@@ -93,7 +93,7 @@ class PainterOptions(object):
options.update(cell.painter_options())
# Also layouts can register painter options
- layout_class = layout_registry.get(view.get("layout"))
+ layout_class = layout_registry.get(view.spec.get("layout"))
if layout_class:
options.update(layout_class().painter_options)
@@ -119,18 +119,18 @@ class PainterOptions(object):
vo[view_name] = self._options
config.user.save_file("viewoptions", vo)
- def update_from_url(self, view_name, view):
+ def update_from_url(self, view):
self._load_used_options(view)
if not self.painter_option_form_enabled():
return
if html.request.has_var("_reset_painter_options"):
- self._clear_painter_options(view_name)
+ self._clear_painter_options(view.name)
return
elif html.request.has_var("_update_painter_options"):
- self._set_from_submitted_form(view_name)
+ self._set_from_submitted_form(view.name)
def _set_from_submitted_form(self, view_name):
# TODO: Remove all keys that are in painter_option_registry
@@ -1596,8 +1596,8 @@ def painter_exists(painter_spec):
return painter_name in painter_registry
-# A cell is an instance of a painter in a view (-> a cell or a grouping cell)
class Cell(object):
+ """A cell is an instance of a painter in a view (-> a cell or a
grouping cell)"""
# Wanted to have the "parse painter spec logic" in one place (The Cell()
class)
# but this should be cleaned up more. TODO: Move this to another place
@@ -1746,7 +1746,7 @@ class Cell(object):
onclick = ''
title = ''
if display_options.enabled(display_options.L) \
- and self._view.get('user_sortable', False) \
+ and self._view.spec.get('user_sortable', False) \
and get_sorter_name_of_painter(self.painter_name()) is not None:
params = [
('sort', self._sort_url()),
@@ -1754,7 +1754,7 @@ class Cell(object):
if display_options.title_options:
params.append(('display_options',
display_options.title_options))
- classes += ["sort", get_primary_sorter_order(self._view,
self.painter_name())]
+ classes += ["sort", get_primary_sorter_order(self._view.spec,
self.painter_name())]
onclick = "location.href=\'%s\'" % html.makeuri(params,
'sort')
title = _('Sort by %s') % self.title()
@@ -1776,7 +1776,7 @@ class Cell(object):
"""
sorter = []
- group_sort, user_sort, view_sort = get_separated_sorters(self._view)
+ group_sort, user_sort, view_sort = get_separated_sorters(self._view.spec)
sorter = group_sort + user_sort + view_sort
@@ -1968,7 +1968,7 @@ class EmptyCell(Cell):
def get_cells(view):
cells = []
- for e in view["painters"]:
+ for e in view.spec["painters"]:
if not painter_exists(e):
continue
@@ -1982,7 +1982,7 @@ def get_cells(view):
def get_group_cells(view):
- return [Cell(view, e) for e in view["group_painters"] if
painter_exists(e)]
+ return [Cell(view, e) for e in view.spec["group_painters"] if
painter_exists(e)]
def output_csv_headers(view):
diff --git a/cmk/gui/views.py b/cmk/gui/views.py
index d1f0087..815e9a8 100644
--- a/cmk/gui/views.py
+++ b/cmk/gui/views.py
@@ -366,7 +366,7 @@ class GUIViewRenderer(ViewRenderer):
pass # currently no feed back on webservice
painter_options = PainterOptions.get_instance()
- painter_options.show_form(view_spec)
+ painter_options.show_form(self.view)
# The refreshing content container
if display_options.enabled(display_options.R):
@@ -1152,7 +1152,7 @@ def page_view():
painter_options = PainterOptions.get_instance()
painter_options.load(view.name)
- painter_options.update_from_url(view.name, view.spec)
+ painter_options.update_from_url(view)
view_renderer = GUIViewRenderer(view, show_buttons=True)
show_view(view, view_renderer)
@@ -1255,8 +1255,8 @@ def show_view(view, view_renderer, only_count=False):
# Group cells: Are displayed as titles of grouped rows
# Regular cells: Are displaying information about the rows of the type the view is
about
# Join cells: Are displaying information of a joined source (e.g.service data on
host views)
- group_cells = get_group_cells(view.spec)
- cells = get_cells(view.spec)
+ group_cells = get_group_cells(view)
+ cells = get_cells(view)
join_cells = get_join_cells(cells)
# Now compute the list of all columns we need to query via Livestatus.
diff --git a/tests/unit/cmk/gui/test_views.py b/tests/unit/cmk/gui/test_views.py
index 731cfed..c55a1f6 100644
--- a/tests/unit/cmk/gui/test_views.py
+++ b/tests/unit/cmk/gui/test_views.py
@@ -5727,8 +5727,8 @@ def test_get_needed_regular_columns(register_builtin_html,
load_view_plugins):
view = cmk.gui.views.View(view_name, view_spec)
sorters = cmk.gui.views._get_sorters(view.spec, user_sort_parameter=None)
- group_cells = cmk.gui.views.get_group_cells(view.spec)
- cells = cmk.gui.views.get_cells(view.spec)
+ group_cells = cmk.gui.views.get_group_cells(view)
+ cells = cmk.gui.views.get_cells(view)
columns = cmk.gui.views._get_needed_regular_columns(group_cells + cells, sorters,
view.datasource)
assert sorted(columns) == sorted([
@@ -5778,7 +5778,7 @@ def test_get_needed_join_columns(register_builtin_html,
load_view_plugins):
view = cmk.gui.views.View(view_name, view_spec)
sorters = cmk.gui.views._get_sorters(view.spec, user_sort_parameter=None)
- cells = cmk.gui.views.get_cells(view.spec)
+ cells = cmk.gui.views.get_cells(view)
join_cells = cmk.gui.views.get_join_cells(cells)
columns = cmk.gui.views._get_needed_join_columns(join_cells, sorters)