annotate data/plugin/macro/DictColumns.py @ 511:ef1f74bf4776

macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 19 Mar 2010 22:59:00 +0100
parents b7a9843c5730
children 31e327c450ca
rev   line source
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3 MoinMoin - macro to collect data from definition lists on pages
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4 into a data browser widget table
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 <<DictColumns(search_term=regex:title:^Examplepage/)>
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 @copyright: 2006 by michael cohen <scudette@users.sourceforge.net> (PageDicts)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
9 @copyright: 2008-2010 by MoinMoin:ReimarBauer (completly rewritten)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10 @license: GNU GPL, see COPYING for details.
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12 import re
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13 from MoinMoin import wikiutil, search
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14 from MoinMoin.Page import Page
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
15 from MoinMoin.action.SlideShow import SlidePage
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 from MoinMoin.util.dataset import TupleDataset, Column
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 from MoinMoin.widget.browser import DataBrowserWidget
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 Dependencies = ["pages"]
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
21
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 def _csv2list(csv):
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 converts a string of comma separated values into a list
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
25 @param csv: string of comma separated values
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26 @returns: list
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28 csv_list = csv.split(',')
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 return [variable.strip() for variable in csv_list if variable.strip()]
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31 def _name2index(all_names, selected_names):
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33 converts names to the index
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34 @param all_names: all available names
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
35 @param selected_names: names to lookup index position of all_names
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
36 @return: list of indices
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
37 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
38 if selected_names:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 try:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40 index = [all_names.index(name) for name in selected_names]
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41 except ValueError:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42 return []
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 return index
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44 return []
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46 class DictColumns(object):
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48 Collects definition list key and values pairs.
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49 Each key becomes a column with its values.
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
50 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 def __init__(self, macro, pagename=u'', title=u'', names=u'',
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
52 sort=u'', reverse=u'',
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53 hide=u'', filter_name=u'NeverExistingDefaultFilter',
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54 filter_value=u'', template_page=u'', alias_page=u'',
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
55 parser=u'text_moin_wiki', markup="definition list", search_term=None):
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
56
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57 self.formatter = macro.formatter
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58 self.request = macro.request
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 self.pagename = pagename
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60 if not pagename:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
61 self.pagename = macro.formatter.page.page_name
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
62 self.title = title
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
63 if not title:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
64 self.title = self.pagename
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
65 self.names = names
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
66 self.sort = sort
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
67 self.reverse = reverse
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
68 self.hide = hide
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
69 self.filter_name = filter_name
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
70 self.filter_value = filter_value
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
71 self.filter_key, self.filter_word = (u"", u"")
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
72 regex = re.compile(ur'(?P<key>\w*)=(?P<value>.*)', re.UNICODE)
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73 try:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
74 self.filter_key, self.filter_word = regex.search(filter_value).groups()
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
75 except AttributeError:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
76 # Don't filter if syntax was wrong
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
77 self.filter_value = u""
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
78 self.template_page = template_page
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
79 self.alias_page = alias_page
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
80 try:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
81 self.wiki_parser = wikiutil.importPlugin(
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
82 self.request.cfg, "parser",
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
83 parser, function="Parser")
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
84 except wikiutil.PluginMissingError:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
85 self.wiki_parser = None
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
86 self.search_term = search_term
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
87 self.markup = markup
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
88 if search_term is None:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
89 self.search_term = u'regex:title:^%s/' % self.pagename
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
90
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
91 def get_dict(self, dict_source):
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
92 """
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
93 gets the dictionary dependent of the markup
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
94 @param dict_source: pagename to read dict data from
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
95 """
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
96 if self.markup == "definition list":
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
97 return self.request.dicts[dict_source]
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
98 elif self.markup == "title":
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
99 return self.parse_title(dict_source)
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
100
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
101 def parse_title(self, dict_source):
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
102 """
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
103 creates a dictionary based on page titles
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
104 @param dict_source: pagename to read dict data from
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
105 """
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
106 body = Page(self.request, dict_source).get_raw_body()
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
107 parser = SlidePage(self.request, dict_source).createSlideParser()
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
108 ddict = {}
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
109 for title, bodyStart, bodyEnd in parser.parse(body):
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
110 ddict[title] = body[bodyStart:bodyEnd].strip()
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
111 return ddict
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
112
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
113 def get_page_list(self):
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
114 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
115 selects the pages dependent on a search term,
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
116 without listing of template, dictionary pages and
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
117 the pagename itselfs.
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
118 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
119 request = self.request
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
120 search_term = self.search_term
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
121 search_result = search.searchPages(request, search_term)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
122 pages = [title.page_name for title in search_result.hits]
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
123 if not pages:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
124 return None
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
125 # exclude some_pages
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
126 filterfn = request.cfg.cache.page_template_regexact.search
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
127 template_pages = request.rootpage.getPageList(filter=filterfn)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
128 excluded_pages = template_pages + [self.alias_page, self.pagename]
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
129 selected_pages = [page for page in pages if page not in excluded_pages]
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
130 selected_pages.sort()
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
131 return selected_pages
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
132
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
133 def get_names(self, selected_pages):
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
134 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
135 selects which column names should be used
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
136 @param selected_pages: list of page names
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
137 @return: list of names
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
138 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
139 request = self.request
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
140 # use selection and order
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
141 if self.names:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
142 names = self.names
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
143 # use keys from template page, no order
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
144 elif Page(request, self.template_page).exists():
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
145 page_dict = self.get_dict(self.template_page)
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
146 names = page_dict.keys()
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
147 else:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
148 # fallback use the keys used on selected pages
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
149 names = []
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
150 for page_name in selected_pages:
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
151 page_dict = self.get_dict(page_name)
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
152 keys = page_dict.keys()
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
153 names = names + keys
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
154 return list(set(names))
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
155
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
156 def dataset(self, names, selected_pages):
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
157 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
158 Sets the data for the data browser widget
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
159 @param names: column names
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
160 @param selected_pages: pages to read key value pairs from
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
161 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
162 assert isinstance(selected_pages, list)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
163 request = self.request
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
164 hide_columns = self.hide
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
165 # default alias
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
166 alias_dict = {}
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
167 for name in names:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
168 alias_dict[name] = name
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
169 if Page(request, self.alias_page).exists():
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
170 alias = self.get_dict(self.alias_page)
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
171 for name in names:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
172 alias_dict[name] = alias.get(name, name)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
173
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
174 col = Column(self.title, label=self.title)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
175 if self.title in hide_columns:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
176 col.hidden = True
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
177
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
178 data = TupleDataset()
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
179 data.columns = []
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
180 data.columns.extend([col])
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
181
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
182 for page_name in selected_pages:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
183 page = Page(request, page_name)
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
184 page_dict = self.get_dict(page_name)
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
185 if self.filter_value and page_dict.get(self.filter_key, '') != self.filter_word:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
186 continue
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
187
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
188 row = []
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
189 for name in names:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
190 if name in page_dict.keys():
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
191 value = page_dict.get(name, '')
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
192 value = value.replace('attachment:', 'attachment:%s/' % name)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
193 if self.wiki_parser:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
194 row.append((wikiutil.renderText(request, self.wiki_parser, value),
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
195 wikiutil.escape(value, 1)))
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
196 else:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
197 row.append('')
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
198 try:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
199 parent, child = page_name.split('/', 1)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
200 except ValueError:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
201 child = page_name
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
202 link = page.link_to(request, text="%s" % child)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
203 data.addRow([link] + row)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
204
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
205 if self.filter_name:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
206 filtercols = self.filter_name
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
207 for name in names:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
208 if self.filter_name != u'NeverExistingDefaultFilter' and name in filtercols:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
209 col = Column(alias_dict[name], autofilter=(name in filtercols))
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
210 if name in hide_columns:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
211 col.hidden = True
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
212 data.columns.append(col)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
213 else:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
214 col = Column(alias_dict[name], label=alias_dict[name])
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
215 if name in hide_columns:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
216 col.hidden = True
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
217 data.columns.extend([col])
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
218
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
219 return data
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
220
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
221 def render(self):
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
222 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
223 renders output as widget data browser table
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
224 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
225 request = self.request
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
226 _ = request.getText
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
227
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
228 selected_pages = self.get_page_list()
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
229 if not selected_pages:
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
230 return _("""\
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
231 Please use a more selective search term instead of search_term="%s"\
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
232 """) % self.search_term
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
233
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
234 names = self.get_names(selected_pages)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
235
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
236 data = self.dataset(names, selected_pages)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
237 table = DataBrowserWidget(request)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
238
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
239 names.insert(0, "__name__")
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
240 sort_columns = _name2index(names, self.sort)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
241 sort_reverse_columns = _name2index(names, self.reverse) or False
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
242
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
243 table.setData(data, sort_columns, reverse=sort_reverse_columns)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
244 html = ''.join(table.format(method='GET'))
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
245 return html
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
246
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
247 def macro_DictColumns(macro, pagename=unicode, title=u'', names=u'', sort=u'', reverse=u'',
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
248 hide=u'', filter_name=u'NeverExistingDefaultFilter',
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
249 filter_value=u'', template_page=u'', alias_page=u'',
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
250 parser=u'text_moin_wiki', markup=("definition list", "title"),
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
251 search_term=None):
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
252 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
253 Creates a table by data browser widget from definition lists key value pairs.
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
254 @param pagename: name of the page
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
255 @param title: entry in upper left corner of the table
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
256 @param name: names of columns, key name of definition list (comma separated)
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
257 @param sort: name of columns to sort by
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
258 @param reverse: name of columns to reverse sort by
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
259 @param hide: name of columns to hide
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
260 @param filter_name: name of columns to filter by autofilter
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
261 @param filter_value: dict definition for value of column to filter by
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
262 @param template_page: pagename of the template for setting column names
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
263 @param alias_page: pagename of the page for setting aliases for column names
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
264 @param parser: name of the parser used to render markup
511
ef1f74bf4776 macro DictColumns: new keyword markup defined (default is "definition list"). By setting it to "title" the column headings are defined by the titles of the pageThe text below a title becomes assigned to the column.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 506
diff changeset
265 @param markup: type of markup for separating key value pairs
506
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
266 @param search_term: regex used to search for selecting pages
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
267 """
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
268 kw = locals()
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
269 # wiki input can be a string with comma separated values.
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
270 kw["names"] = _csv2list(kw["names"])
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
271 kw["sort"] = _csv2list(kw["sort"])
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
272 kw["reverse"] = _csv2list(kw["reverse"])
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
273 kw["hide"] = _csv2list(kw["hide"])
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
274 kw["filter_name"] = _csv2list(kw["filter_name"])
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
275 html = DictColumns(**kw).render()
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
276 # works together with
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
277 # http://moinmo.in/FeatureRequests/SortableTables?action=AttachFile&do=view&target=common.js.patch
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
278 # html = html.replace('id="dbw.table', 'class="sortable" id="dbw.table')
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
279 return html
b7a9843c5730 macro DictColumns:Collects definition list key and values pairs. Each key becomes a column with its values.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
280