changeset 353:51772c48c3eb

CollectLists: replaced filter_pattern by filter_column_value. You can preselect rows to show up only if a key value pair is equal to a given definition e.g. filter_column_value=project:: 1.7-extensions
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 05 Feb 2009 08:38:49 +0100
parents 2b139cd6c4d7
children 8b431b302c79
files data/plugin/macro/CollectLists.py
diffstat 1 files changed, 15 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/macro/CollectLists.py	Wed Feb 04 15:08:20 2009 +0100
+++ b/data/plugin/macro/CollectLists.py	Thu Feb 05 08:38:49 2009 +0100
@@ -10,8 +10,8 @@
     or the column_heading. In the latter case the order is used. Also it can optionally use
     another pagename. By setting optional a parser one can use e.g. wikimarkup. By
     filter_selection you can optional use the filter method of the databrowser widget.
-    By using a different filter_pattern than '.*' you get only rows shown where that
-    pattern was found.
+    By using a different filter_column_value than '', eg. name:: Cohen  you get only rows shown where that
+    name was found.
 
     @copyright: 2006 by michael cohen <scudette@users.sourceforge.net> (PageDicts)
     @copyright: 2008-2009 by MoinMoin:ReimarBauer (completly rewritten)
@@ -30,13 +30,12 @@
                       align=("left", "center", "right"),
                       column_heading=u'', template=u'',
                       transpose=False,
-                      filter_pattern=u'.*',
+                      filter_column_value=u'',
                       parser=u'text_moin_wiki',
                       filter_selection=u'NeverExistingDefaultFilter'):
 
     """
     currently we don't support transpose together with filter_selection
-    removing columns by filter_pattern and transpose is not implemented yet
     """
     request = macro.request
     formatter = macro.formatter
@@ -48,6 +47,14 @@
 
     if not pagename:
         pagename = formatter.page.page_name
+        
+    if filter_column_value and ':: ' in filter_column_value:
+        filter_key, filter_word = filter_column_value.split('::')
+        filter_key = filter_key.strip()
+        filter_word = filter_word.strip()
+    else:
+        # Don't filter if syntax was wrong
+        filter_column_value = u''
 
     needle = '^%s/(.*)' % pagename
     filterfn = re.compile(needle).search
@@ -85,12 +92,13 @@
     for name in subpages:
         page = Page(request, name)
         page_dict = Dict(request, name)
+        if filter_column_value and page_dict.get(filter_key, '') != filter_word:
+            continue
         row = []
-        tmp_string = []
+        keep = False
         for key in column_heading_keys:
             if key in page_dict.keys():
                 value = page_dict.get(key, '')
-                tmp_string.append(value)
                 if WikiParser:
                     # xxx check how our brand new Image class solves this
                     if parser == u'text_moin_wiki':
@@ -102,11 +110,7 @@
                 row.append('')
         parent, child = name.split('/', 1)
         link = page.link_to(request, text="/%s" % child)
-        tmp_string = ''.join(tmp_string)
-        search_result = re.search(filter_pattern, tmp_string)
-        # ToDo removing columns by filter_pattern and transpose is not implemented yet
-        if tmp_string and search_result or transpose:
-            data.addRow([link] + row)
+        data.addRow([link] + row)
         if transpose:
             data.columns.extend([Column(link, label=link, align=align)])