changeset 491:435dc7e10d78

CollectLists: new keyword dictionary introduced. A given page is readed and the column_header labels are replaced by the values given on the list there. Also fixed that not only subpages can be used by this macro.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 03 Feb 2010 20:39:25 +0100
parents d89a77a21e55
children 000965a6e265
files data/plugin/macro/CollectLists.py
diffstat 1 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/macro/CollectLists.py	Wed Feb 03 18:10:22 2010 +0100
+++ b/data/plugin/macro/CollectLists.py	Wed Feb 03 20:39:25 2010 +0100
@@ -35,7 +35,9 @@
 
 def macro_CollectLists(macro, pagename=unicode,
                       align=("left", "center", "right"),
-                      column_heading=u'', template=u'',
+                      column_heading=u'',
+                      template=u'',
+                      dictionary=u'',
                       transpose=False,
                       filter_column_value=u'',
                       parser=u'text_moin_wiki',
@@ -66,7 +68,7 @@
         filter_column_value = u''
 
     if search_expression is None:
-        search_expression = 'title:%s/' % pagename
+        search_expression = u'regex:title:%s/' % pagename
 
     search_result = search.searchPages(request, search_expression)
     pages = [title.page_name for title in search_result.hits]
@@ -77,7 +79,7 @@
     # ignore Template pages
     filterfn = request.cfg.cache.page_template_regexact.search
     templates = request.rootpage.getPageList(filter=filterfn)
-    subpages = [page for page in pages if page not in templates]
+    subpages = [page for page in pages if page not in [templates, dictionary, pagename]]
     if not subpages:
         return _("Subpage of '%(pagename)s' does not exist or you don't have enough rights.") % {"pagename": pagename}
     subpages.sort()
@@ -96,12 +98,20 @@
         page_dict = Dict(request, subpages[0])
         column_heading_keys = page_dict.keys()
 
+    # default alias
+    alias_dict = {}
+    for key in column_heading_keys:
+        alias_dict[key] = key
+    if Page(request, dictionary).exists():
+        alias_dict = Dict(request, dictionary)
+        heading_keys = [alias_dict[key] for key in column_heading_keys]
+        
     data = TupleDataset()
     data.columns = []
     data.columns.extend([Column(pagename.strip('/'), label=pagename.strip('/'), align=align)])
     # may be transpose should be moved into the databrowser widget
     if transpose:
-        data.addRow([pagename.strip('/')] + column_heading_keys)
+        data.addRow([pagename.strip('/')] + heading_keys)
 
     for name in subpages:
         page = Page(request, name)
@@ -122,7 +132,11 @@
                     row.append((wikiutil.escape(value, 1), wikiutil.escape(value, 1)))
             else:
                 row.append('')
-        parent, child = name.split('/', 1)
+        try:
+            parent, child = name.split('/', 1)
+        except ValueError:
+            parent = pagename
+            child = name
         link = page.link_to(request, text="%s" % child)
         data.addRow([link] + row)
         if transpose:
@@ -140,7 +154,7 @@
                 if filter_selection != u'NeverExistingDefaultFilter' and key in filtercols:
                     data.columns.append(Column(key, autofilter=(key in filtercols)))
                 else:
-                    data.columns.extend([Column(key, label=key, align=align)])
+                    data.columns.extend([Column(key, label=alias_dict[key], align=align)])
 
     table = DataBrowserWidget(request)
     table.setData(data)