Module: check_mk
Branch: master
Commit: 802aa0a1936274630d2b40531e327787be9b709d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=802aa0a1936274…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 4 19:54:04 2019 +0100
Moved join_columns to join implementation
Change-Id: I3ed2b1a62dde6ed2a9dd3e8b5969a08da736ea5d
---
cmk/gui/views.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/cmk/gui/views.py b/cmk/gui/views.py
index f3d9b17..033e7ee 100644
--- a/cmk/gui/views.py
+++ b/cmk/gui/views.py
@@ -1317,7 +1317,6 @@ def show_view(view, view_renderer, only_count=False):
# Prepare cells of the view
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
@@ -1326,7 +1325,6 @@ def show_view(view, view_renderer, only_count=False):
# is the trickiest. Also compute this list of view options use by the
# painters
columns = _get_needed_regular_columns(group_cells + cells, sorters, view.datasource)
- join_columns = _get_needed_join_columns(join_cells, sorters)
# Fetch data. Some views show data only after pressing [Search]
if (only_count or (not view.spec.get("mustsearch")) or
@@ -1335,8 +1333,8 @@ def show_view(view, view_renderer, only_count=False):
all_active_filters)
# Now add join information, if there are join columns
- if join_cells:
- _do_table_join(view, rows, filterheaders, join_cells, join_columns)
+ if view.join_cells:
+ _do_table_join(view, rows, filterheaders, sorters)
# If any painter, sorter or filter needs the information about the host's
# inventory, then we load it and attach it as column "host_inventory"
@@ -1494,10 +1492,12 @@ def columns_of_cells(cells):
return columns
-def _do_table_join(view, master_rows, master_filters, join_cells, join_columns):
+def _do_table_join(view, master_rows, master_filters, sorters):
join_table, join_master_column = view.datasource.join
slave_ds = data_source_registry[join_table]()
join_slave_column = slave_ds.join_key
+ join_cells = view.join_cells
+ join_columns = _get_needed_join_columns(join_cells, sorters)
# Create additional filters
join_filters = []
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',
Module: check_mk
Branch: master
Commit: 03c3c9bbea1f24de857fc13a9db17d0e21c62303
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=03c3c9bbea1f24…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 4 15:18:49 2019 +0100
Move user sorter handling to View
* The configured sorting of the rows may be modified by the user
by clicking on the column header
* The user sets the HTTP variable "sort" in this moment
* Moved processing of this HTTP variable out of show_view() and
_get_separated_sorters().
* The HTTP variable is now processed equal to other user modifyable
variables (row_limit and only_sites at the moment) and set on
the View() instances to make it avaiable to other code parts.
Change-Id: Ibf79c222878067d3c61d5a1cdd5300af1e12bd7b
---
cmk/gui/mobile.py | 2 ++
cmk/gui/plugins/dashboard/view.py | 1 +
cmk/gui/plugins/views/utils.py | 51 +++++++++++++--------------------------
cmk/gui/views.py | 47 +++++++++++++++++++++++++++++-------
tests/unit/cmk/gui/test_views.py | 14 +++++++++--
5 files changed, 70 insertions(+), 45 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=03c3c9bbea…