comparison data/plugin/macro/CollectLists.py @ 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
comparison
equal deleted inserted replaced
352:2b139cd6c4d7 353:51772c48c3eb
8 the data from each key value pair 8 the data from each key value pair
9 optional you can give the template page the definition list page depends on 9 optional you can give the template page the definition list page depends on
10 or the column_heading. In the latter case the order is used. Also it can optionally use 10 or the column_heading. In the latter case the order is used. Also it can optionally use
11 another pagename. By setting optional a parser one can use e.g. wikimarkup. By 11 another pagename. By setting optional a parser one can use e.g. wikimarkup. By
12 filter_selection you can optional use the filter method of the databrowser widget. 12 filter_selection you can optional use the filter method of the databrowser widget.
13 By using a different filter_pattern than '.*' you get only rows shown where that 13 By using a different filter_column_value than '', eg. name:: Cohen you get only rows shown where that
14 pattern was found. 14 name was found.
15 15
16 @copyright: 2006 by michael cohen <scudette@users.sourceforge.net> (PageDicts) 16 @copyright: 2006 by michael cohen <scudette@users.sourceforge.net> (PageDicts)
17 @copyright: 2008-2009 by MoinMoin:ReimarBauer (completly rewritten) 17 @copyright: 2008-2009 by MoinMoin:ReimarBauer (completly rewritten)
18 @license: GNU GPL, see COPYING for details. 18 @license: GNU GPL, see COPYING for details.
19 """ 19 """
28 28
29 def macro_CollectLists(macro, pagename=unicode, 29 def macro_CollectLists(macro, pagename=unicode,
30 align=("left", "center", "right"), 30 align=("left", "center", "right"),
31 column_heading=u'', template=u'', 31 column_heading=u'', template=u'',
32 transpose=False, 32 transpose=False,
33 filter_pattern=u'.*', 33 filter_column_value=u'',
34 parser=u'text_moin_wiki', 34 parser=u'text_moin_wiki',
35 filter_selection=u'NeverExistingDefaultFilter'): 35 filter_selection=u'NeverExistingDefaultFilter'):
36 36
37 """ 37 """
38 currently we don't support transpose together with filter_selection 38 currently we don't support transpose together with filter_selection
39 removing columns by filter_pattern and transpose is not implemented yet
40 """ 39 """
41 request = macro.request 40 request = macro.request
42 formatter = macro.formatter 41 formatter = macro.formatter
43 42
44 try: 43 try:
46 except wikiutil.PluginMissingError: 45 except wikiutil.PluginMissingError:
47 WikiParser = None 46 WikiParser = None
48 47
49 if not pagename: 48 if not pagename:
50 pagename = formatter.page.page_name 49 pagename = formatter.page.page_name
50
51 if filter_column_value and ':: ' in filter_column_value:
52 filter_key, filter_word = filter_column_value.split('::')
53 filter_key = filter_key.strip()
54 filter_word = filter_word.strip()
55 else:
56 # Don't filter if syntax was wrong
57 filter_column_value = u''
51 58
52 needle = '^%s/(.*)' % pagename 59 needle = '^%s/(.*)' % pagename
53 filterfn = re.compile(needle).search 60 filterfn = re.compile(needle).search
54 pages = request.rootpage.getPageList(exists=1, filter=filterfn) 61 pages = request.rootpage.getPageList(exists=1, filter=filterfn)
55 if not pages: 62 if not pages:
83 data.addRow([pagename.strip('/')] + column_heading_keys) 90 data.addRow([pagename.strip('/')] + column_heading_keys)
84 91
85 for name in subpages: 92 for name in subpages:
86 page = Page(request, name) 93 page = Page(request, name)
87 page_dict = Dict(request, name) 94 page_dict = Dict(request, name)
95 if filter_column_value and page_dict.get(filter_key, '') != filter_word:
96 continue
88 row = [] 97 row = []
89 tmp_string = [] 98 keep = False
90 for key in column_heading_keys: 99 for key in column_heading_keys:
91 if key in page_dict.keys(): 100 if key in page_dict.keys():
92 value = page_dict.get(key, '') 101 value = page_dict.get(key, '')
93 tmp_string.append(value)
94 if WikiParser: 102 if WikiParser:
95 # xxx check how our brand new Image class solves this 103 # xxx check how our brand new Image class solves this
96 if parser == u'text_moin_wiki': 104 if parser == u'text_moin_wiki':
97 value = value.replace('attachment:', 'attachment:%s/' % name) 105 value = value.replace('attachment:', 'attachment:%s/' % name)
98 row.append((wikiutil.renderText(request, WikiParser, value), wikiutil.escape(value, 1))) 106 row.append((wikiutil.renderText(request, WikiParser, value), wikiutil.escape(value, 1)))
100 row.append((wikiutil.escape(value, 1), wikiutil.escape(value, 1))) 108 row.append((wikiutil.escape(value, 1), wikiutil.escape(value, 1)))
101 else: 109 else:
102 row.append('') 110 row.append('')
103 parent, child = name.split('/', 1) 111 parent, child = name.split('/', 1)
104 link = page.link_to(request, text="/%s" % child) 112 link = page.link_to(request, text="/%s" % child)
105 tmp_string = ''.join(tmp_string) 113 data.addRow([link] + row)
106 search_result = re.search(filter_pattern, tmp_string)
107 # ToDo removing columns by filter_pattern and transpose is not implemented yet
108 if tmp_string and search_result or transpose:
109 data.addRow([link] + row)
110 if transpose: 114 if transpose:
111 data.columns.extend([Column(link, label=link, align=align)]) 115 data.columns.extend([Column(link, label=link, align=align)])
112 116
113 if transpose: 117 if transpose:
114 data.data = map(None, zip(*data.data)) 118 data.data = map(None, zip(*data.data))