Module: check_mk
Branch: master
Commit: 45b222c68566e5c9e859d27ce2e08ebbfb21d105
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=45b222c68566e5…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Tue Jan 10 10:52:20 2017 +0100
Refactoring table.py: Moved functions around.
Change-Id: I3c98ae9e0a323bd62e79bc1c64ca41d004c5c189
---
web/htdocs/table.py | 144 ++++++++++++++++++++++++++--------------------------
1 file changed, 72 insertions(+), 72 deletions(-)
diff --git a/web/htdocs/table.py b/web/htdocs/table.py
index da107c8..5de76aa 100644
--- a/web/htdocs/table.py
+++ b/web/htdocs/table.py
@@ -129,77 +129,6 @@ def add_cell(title="", text="", css=None,
help=None, colspan=None, sortable=True
table["rows"][-1][0].append((htmlcode, css, colspan))
-def _filter_rows(rows, search_term):
- filtered_rows = []
- for row, css, state, fixed in rows:
- if state == "header" or fixed:
- filtered_rows.append((row, css, state, fixed))
- continue # skip filtering of headers or fixed rows
-
- for cell_content, css_classes, colspan in row:
- if search_term in cell_content.lower():
- filtered_rows.append((row, css, state, fixed))
- break # skip other cells when matched
- return filtered_rows
-
-
-def _sort_rows(rows, sort_col, sort_reverse):
-
- # remove and remind fixed rows, add to separate list
- fixed_rows = []
- for index, row in enumerate(rows[:]):
- if row[3] == True:
- rows.remove(row)
- fixed_rows.append((index, row))
-
- # Then use natural sorting to sort the list. Note: due to a
- # change in the number of columns of a table in different software
- # versions the cmp-function might fail. This is because the sorting
- # column is persisted in a user file. So we ignore exceptions during
- # sorting. This gives the user the chance to change the sorting and
- # see the table in the first place.
- try:
- rows.sort(cmp=lambda a, b: cmp(num_split(a[0][sort_col][0]),
- num_split(b[0][sort_col][0])),
- reverse=sort_reverse==1)
- except IndexError:
- pass
-
- # Now re-add the removed "fixed" rows to the list again
- if fixed_rows:
- for index, row in fixed_rows:
- rows.insert(index, row)
-
- return rows
-
-
-def _write_csv(table, csv_separator):
-
- rows = table["rows"]
- headers = table["headers"]
- limit = table['limit']
- omit_headers = table["omit_headers"]
-
- num_rows_unlimited = len(rows)
- num_cols = len(headers)
-
- # Apply limit after search / sorting etc.
- if limit is not None:
- rows = rows[:limit]
-
- def render_headers():
- html.write(csv_separator.join([html.strip_tags(header) or "" for
(header, css, help, sortable) in headers]) + "\n")
-
- # If we have no group headers then paint the headers now
- if not omit_headers and table["rows"] and table["rows"][0][2] !=
"header":
- render_headers()
-
- odd = "even"
- for nr, (row, css, state, fixed) in enumerate(rows):
- html.write(csv_separator.join([html.strip_tags(cell_content) for cell_content,
css_classes, colspan in row ]))
- html.write("\n")
-
-
def end():
global table
finish_previous()
@@ -223,7 +152,6 @@ def end():
table = None
return
-
if do_csv:
_write_csv(table, csv_separator)
table = None
@@ -427,3 +355,75 @@ def end():
table = None
+def _write_csv(table, csv_separator):
+
+ rows = table["rows"]
+ headers = table["headers"]
+ limit = table['limit']
+ omit_headers = table["omit_headers"]
+
+ num_rows_unlimited = len(rows)
+ num_cols = len(headers)
+
+ # Apply limit after search / sorting etc.
+ if limit is not None:
+ rows = rows[:limit]
+
+ def render_headers():
+ html.write(csv_separator.join([html.strip_tags(header) or "" for
(header, css, help, sortable) in headers]) + "\n")
+
+ # If we have no group headers then paint the headers now
+ if not omit_headers and table["rows"] and table["rows"][0][2] !=
"header":
+ render_headers()
+
+ odd = "even"
+ for nr, (row, css, state, fixed) in enumerate(rows):
+ html.write(csv_separator.join([html.strip_tags(cell_content) for cell_content,
css_classes, colspan in row ]))
+ html.write("\n")
+
+
+
+def _filter_rows(rows, search_term):
+ filtered_rows = []
+ for row, css, state, fixed in rows:
+ if state == "header" or fixed:
+ filtered_rows.append((row, css, state, fixed))
+ continue # skip filtering of headers or fixed rows
+
+ for cell_content, css_classes, colspan in row:
+ if search_term in cell_content.lower():
+ filtered_rows.append((row, css, state, fixed))
+ break # skip other cells when matched
+ return filtered_rows
+
+
+def _sort_rows(rows, sort_col, sort_reverse):
+
+ # remove and remind fixed rows, add to separate list
+ fixed_rows = []
+ for index, row in enumerate(rows[:]):
+ if row[3] == True:
+ rows.remove(row)
+ fixed_rows.append((index, row))
+
+ # Then use natural sorting to sort the list. Note: due to a
+ # change in the number of columns of a table in different software
+ # versions the cmp-function might fail. This is because the sorting
+ # column is persisted in a user file. So we ignore exceptions during
+ # sorting. This gives the user the chance to change the sorting and
+ # see the table in the first place.
+ try:
+ rows.sort(cmp=lambda a, b: cmp(num_split(a[0][sort_col][0]),
+ num_split(b[0][sort_col][0])),
+ reverse=sort_reverse==1)
+ except IndexError:
+ pass
+
+ # Now re-add the removed "fixed" rows to the list again
+ if fixed_rows:
+ for index, row in fixed_rows:
+ rows.insert(index, row)
+
+ return rows
+
+