Module: check_mk
Branch: master
Commit: 6da128f5c96e3c0f86b0697e9b08efb5b0cbec09
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6da128f5c96e3c…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Tue Jan 10 16:24:20 2017 +0100
Refactoring table.py: Moving out evaluation of user_opts.
Change-Id: I9805b98cb7b67c62d067581bb3ebdd3159a49ce3
---
web/htdocs/table.py | 55 ++++++++++++++++++++++++++++++++---------------------
1 file changed, 33 insertions(+), 22 deletions(-)
diff --git a/web/htdocs/table.py b/web/htdocs/table.py
index d558a15..3a15d85 100644
--- a/web/htdocs/table.py
+++ b/web/htdocs/table.py
@@ -170,14 +170,43 @@ def end():
table = None
return
- table_id = table['id']
rows = table["rows"]
# Controls whether or not actions are available for a table
+ rows, actions_enabled, actions_visible, search_term, user_opts =
_evaluate_user_opts(table, rows)
+
+ num_rows_unlimited = len(rows)
+ num_cols = len(table["headers"])
+
+ # Apply limit after search / sorting etc.
+ limit = table['limit']
+ if limit is not None:
+ rows = rows[:limit]
+
+ # Render header
+ _write_table(table, rows, actions_enabled, actions_visible, search_term)
+
+ if limit is not None and num_rows_unlimited > limit:
+ html.message(_('This table is limited to show only %d of %d rows. '
+ 'Click <a href="%s">here</a> to disable
the limitation.') %
+ (limit, num_rows_unlimited, html.makeuri([('limit',
'none')])))
+
+ if actions_enabled:
+ config.user.save_file("tableoptions", user_opts)
+ table = None
+
+
+def _evaluate_user_opts(table, rows):
+
+ table_id = table["id"]
+
search_term = None
- actions_visible = False
actions_enabled = (table["searchable"] or table["sortable"])
- if actions_enabled:
+
+ if not actions_enabled:
+ return rows, False, False, None, None
+
+ else:
user_opts = config.user.load_file("tableoptions", {})
user_opts.setdefault(table_id, {})
@@ -217,25 +246,7 @@ def end():
sort_col, sort_reverse = map(int, sort.split(',', 1))
rows = _sort_rows(rows, sort_col, sort_reverse)
- num_rows_unlimited = len(rows)
- num_cols = len(table["headers"])
-
- # Apply limit after search / sorting etc.
- limit = table['limit']
- if limit is not None:
- rows = rows[:limit]
-
- # Render header
- _write_table(table, rows, actions_enabled, actions_visible, search_term)
-
- if limit is not None and num_rows_unlimited > limit:
- html.message(_('This table is limited to show only %d of %d rows. '
- 'Click <a href="%s">here</a> to disable
the limitation.') %
- (limit, num_rows_unlimited, html.makeuri([('limit',
'none')])))
-
- if actions_enabled:
- config.user.save_file("tableoptions", user_opts)
- table = None
+ return rows, actions_enabled, actions_visible, search_term, user_opts
def _write_table(table, rows, actions_enabled, actions_visible, search_term):