Module: check_mk
Branch: master
Commit: 3cf3454f938fee25d824ebe6f5fb2f4631cf0ac1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3cf3454f938feeā¦
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 4 18:24:40 2019 +0100
Move cell collection computation to View class
Change-Id: Ie3ab93296f92f5e439a0bf8b24c103c4b27e9f68
---
cmk/gui/plugins/views/utils.py | 21 +-----------------
cmk/gui/views.py | 47 +++++++++++++++++++++++++++-------------
tests/unit/cmk/gui/test_views.py | 10 ++-------
3 files changed, 35 insertions(+), 43 deletions(-)
diff --git a/cmk/gui/plugins/views/utils.py b/cmk/gui/plugins/views/utils.py
index 2c998cf..dde56d4 100644
--- a/cmk/gui/plugins/views/utils.py
+++ b/cmk/gui/plugins/views/utils.py
@@ -89,7 +89,7 @@ class PainterOptions(object):
def _load_used_options(self, view):
options = set([])
- for cell in get_group_cells(view) + get_cells(view):
+ for cell in view.group_cells + view.row_cells:
options.update(cell.painter_options())
# Also layouts can register painter options
@@ -1966,25 +1966,6 @@ class EmptyCell(Cell):
return False
-def get_cells(view):
- cells = []
- for e in view.spec["painters"]:
- if not painter_exists(e):
- continue
-
- if Cell.is_join_cell(e):
- cells.append(JoinCell(view, e))
-
- else:
- cells.append(Cell(view, e))
-
- return cells
-
-
-def get_group_cells(view):
- return [Cell(view, e) for e in view.spec["group_painters"] if
painter_exists(e)]
-
-
def output_csv_headers(view):
filename = '%s-%s.csv' % (view['name'],
time.strftime('%Y-%m-%d_%H-%M-%S',
time.localtime(time.time())))
diff --git a/cmk/gui/views.py b/cmk/gui/views.py
index fb7efa4..f3d9b17 100644
--- a/cmk/gui/views.py
+++ b/cmk/gui/views.py
@@ -92,6 +92,7 @@ from cmk.gui.plugins.views.utils import (
sorter_registry,
get_permitted_views,
get_all_views,
+ painter_exists,
PainterOptions,
)
@@ -105,7 +106,7 @@ from cmk.gui.plugins.views.utils import ( # pylint:
disable=unused-import
cmp_insensitive_string, cmp_num_split, cmp_custom_variable, cmp_service_name_equiv,
cmp_string_list, cmp_ip_address, get_custom_var, get_perfdata_nth_value,
get_tag_group,
query_data, do_query_data, join_row, get_view_infos, replace_action_url_macros, Cell,
JoinCell,
- get_cells, get_group_cells, register_legacy_command, register_painter,
register_sorter,
+ register_legacy_command, register_painter, register_sorter,
)
# Needed for legacy (pre 1.6) plugins
@@ -228,6 +229,33 @@ class View(object):
"because the datasource does not exist.") % (self.name,
self.datasource))
@property
+ def row_cells(self):
+ # type: () -> List[Cell]
+ """Regular cells are displaying information about the rows of the
type the view is about"""
+ cells = []
+ for e in self.spec["painters"]:
+ if not painter_exists(e):
+ continue
+
+ if Cell.is_join_cell(e):
+ cells.append(JoinCell(self, e))
+ else:
+ cells.append(Cell(self, e))
+
+ return cells
+
+ @property
+ def group_cells(self):
+ # type: () -> List[Cell]
+ """Group cells are displayed as titles of grouped
rows"""
+ return [Cell(self, e) for e in self.spec["group_painters"] if
painter_exists(e)]
+
+ @property
+ def join_cells(self):
+ """Join cells are displaying information of a joined source
(e.g.service data on host views)"""
+ return [x for x in self.row_cells if isinstance(x, JoinCell)]
+
+ @property
def sorters(self):
"""Returns the list of effective sorters to be used to sort the
rows of this view"""
return self._get_sorter_entries(
@@ -1287,12 +1315,9 @@ def show_view(view, view_renderer, only_count=False):
sorters = view.sorters
# Prepare cells of the view
- # 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)
- cells = get_cells(view)
- join_cells = get_join_cells(cells)
+ group_cells = view.group_cells
+ cells = view.row_cells
+ join_cells = view.join_cells
# Now compute the list of all columns we need to query via Livestatus.
# Those are: (1) columns used by the sorters in use, (2) columns use by
@@ -1392,14 +1417,6 @@ def show_view(view, view_renderer, only_count=False):
SorterEntry = namedtuple("SorterEntry", ["sorter",
"negate", "join_key"])
-def get_join_cells(cell_list):
- return [x for x in cell_list if isinstance(x, JoinCell)]
-
-
-def get_regular_cells(cell_list):
- return [x for x in cell_list if isinstance(x, Cell)]
-
-
def _get_needed_regular_columns(cells, sorters, datasource):
# BI availability needs aggr_tree
# TODO: wtf? a full reset of the list? Move this far away to a special place!
diff --git a/tests/unit/cmk/gui/test_views.py b/tests/unit/cmk/gui/test_views.py
index e5d6885..81460aa 100644
--- a/tests/unit/cmk/gui/test_views.py
+++ b/tests/unit/cmk/gui/test_views.py
@@ -5726,10 +5726,7 @@ def test_get_needed_regular_columns(register_builtin_html,
load_view_plugins):
view = cmk.gui.views.View(view_name, 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,
view.sorters, view.datasource)
+ columns = cmk.gui.views._get_needed_regular_columns(view.group_cells +
view.row_cells, view.sorters, view.datasource)
assert sorted(columns) == sorted([
'host_scheduled_downtime_depth',
'host_in_check_period',
@@ -5776,10 +5773,7 @@ def test_get_needed_join_columns(register_builtin_html,
load_view_plugins):
view = cmk.gui.views.View(view_name, 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, view.sorters)
+ columns = cmk.gui.views._get_needed_join_columns(view.join_cells, view.sorters)
assert sorted(columns) == sorted([
'host_name',
'service_description',