annotate MoinMoin/converter/_table.py @ 2940:a3299ab946b6 reyha_verma/fixes-482-1426427038125

close unwanted branch rey...
author RogerHaase <haaserd@gmail.com>
date Tue, 28 Apr 2015 12:52:42 -0700
parents e0afda75944f
children
rev   line source
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
1 # Copyright: 2010 MoinMoin:ThomasWaldmann
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
2 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
3
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 MoinMoin - table data to DOM conversion support
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
6 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8
134
901bd4e1861e import absolute_import, division from __future__ in every module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
9 from __future__ import absolute_import, division
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 from MoinMoin.util.tree import moin_page
1921
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
12 from emeraldtree import ElementTree as ET
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
13
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
14 WORDBREAK_LEN = 30
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1931
diff changeset
16
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 class TableMixin(object):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 Mixin to support building a DOM table.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 """
1931
7dc5085f4960 fix pep8 issue
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1921
diff changeset
21 def add_numeric_class(self, cell, table_cell):
1921
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
22 """
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
23 Add numeric class attribute if cell is numeric.
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
24 """
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
25 try:
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
26 float(cell)
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
27 table_cell.attrib[moin_page('class')] = 'moin-integer'
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
28 except:
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
29 pass
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
30
1118
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
31 def build_dom_table(self, rows, head=None, cls=None):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 Build a DOM table with data from <rows>.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34 """
1118
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
35 table = moin_page.table()
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
36 if cls is not None:
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
37 table.attrib[moin_page('class')] = cls
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
38 if head is not None:
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
39 table_head = moin_page.table_header()
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
40 table_row = moin_page.table_row()
1921
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
41 for idx, cell in enumerate(head):
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
42 table_cell = moin_page.table_cell(children=[cell, ],)
2877
e0afda75944f enhance csv parser - add a header row to thead rather than tbody
RogerHaase <haaserd@gmail.com>
parents: 1975
diff changeset
43 if rows and len(rows[0]) == len(head):
1921
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
44 # add "align: right" to heading cell if cell in first data row is numeric
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
45 self.add_numeric_class(rows[0][idx], table_cell)
1118
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
46 table_row.append(table_cell)
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
47 table_head.append(table_row)
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
48 table.append(table_head)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49 table_body = moin_page.table_body()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50 for row in rows:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 table_row = moin_page.table_row()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 for cell in row:
1921
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
53 if isinstance(cell, ET.Node) and isinstance(cell[0], unicode) and \
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
54 len(cell[0].split()) == 1 and len(cell[0]) > WORDBREAK_LEN:
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
55 # avoid destroying table layout by applying special styling to cells with long file name hyperlinks
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
56 table_cell = moin_page.table_cell(children=[cell, ], attrib={moin_page.class_: 'moin-wordbreak'})
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
57 else:
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
58 table_cell = moin_page.table_cell(children=[cell, ],)
0fbb4321de4a improve display of archive member list, right align size, omit directories, remove T from timestamp
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1397
diff changeset
59 self.add_numeric_class(cell, table_cell)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 table_row.append(table_cell)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 table_body.append(table_row)
1118
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
62 table.append(table_body)
505ad860856a Added table header for archive content listing.
Julian Brost <julian.brost@googlemail.com>
parents: 134
diff changeset
63 return table