changeset 2610:c9dddf691d7b

jp (common): allow tables filters callbacks to have only one argument
author Goffi <goffi@goffi.org>
date Thu, 21 Jun 2018 01:21:34 +0200
parents 75d2ac872965
children c180ca699e72
files sat_frontends/jp/common.py
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/common.py	Wed Jun 06 19:24:15 2018 +0200
+++ b/sat_frontends/jp/common.py	Thu Jun 21 01:21:34 2018 +0200
@@ -410,7 +410,11 @@
         @param headers(iterable[unicode], None): names/titles of the columns
             if not None, must have same number of columns as data
         @param filters(iterable[(callable, unicode)], None): values filters
-            the callable will get col value as argument and must return a string
+            the callable will get 2 arguments:
+                - current column value
+                - RowData with all columns values
+            if may also only use 1 argument, which will then be current col value.
+            the callable must return a string
             if it's unicode, it will be used with .format and must countain u'{}' which will be replaced with the string
             if not None, must have same number of columns as data
         @param use_buffer(bool): if True, bufferise output instead of printing it directly
@@ -440,7 +444,10 @@
                     if isinstance(filter_, basestring):
                         col_value = filter_.format(value)
                     else:
-                        col_value = filter_(value, row_cls(*row_data_list))
+                        try:
+                            col_value = filter_(value, row_cls(*row_data_list))
+                        except TypeError:
+                            col_value = filter_(value)
                     # we count size without ANSI code as they will change length of the string
                     # when it's mostly style/color changes.
                     col_size = len(regex.ansiRemove(col_value))
@@ -497,8 +504,7 @@
         @param headers(iterable[unicode], None): name of the columns
             names must be in same order as keys
         @param filters(dict[unicode, (callable,unicode)), None): filter to use on values
-            keys correspond to keys to filter, and value is a callable or unicode which
-            will get the value as argument and must return a string
+            keys correspond to keys to filter, and value is the same as for Table.__init__
         @param defaults(dict[unicode, unicode]): default value to use
             if None, an exception will be raised if not value is found
         """