-
Notifications
You must be signed in to change notification settings - Fork 44
/
rows.py
66 lines (50 loc) · 1.23 KB
/
rows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from flask_table import Table, Col
class Item(object):
def __init__(self, name, description):
self.name = name
self.description = description
def important(self):
"""Items are important if their description starts with an a.
"""
return self.description.lower().startswith('a')
class ItemTable(Table):
name = Col('Name')
description = Col('Description')
def get_tr_attrs(self, item):
if item.important():
return {'class': 'important'}
else:
return {}
def main():
items = [Item('Name1', 'Boring'),
Item('Name2', 'A very important item'),
Item('Name3', 'Boring')]
table = ItemTable(items)
print(table.__html__())
"""
Outputs:
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name1</td>
<td>Boring</td>
</tr>
<tr class="important">
<td>Name2</td>
<td>A very important item</td>
</tr>
<tr>
<td>Name3</td>
<td>Boring</td>
</tr>
</tbody>
</table>
"""
if __name__ == '__main__':
main()