-
Notifications
You must be signed in to change notification settings - Fork 44
/
simple.py
61 lines (46 loc) · 1.19 KB
/
simple.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
from flask_table import Table, Col
"""Lets suppose that we have a class that we get an iterable of from
somewhere, such as a database. We can declare a table that pulls out
the relevant entries, escapes them and displays them.
"""
class Item(object):
def __init__(self, name, description):
self.name = name
self.description = description
class ItemTable(Table):
name = Col('Name')
description = Col('Description')
def main():
items = [Item('Name1', 'Description1'),
Item('Name2', 'Description2'),
Item('Name3', 'Description3')]
table = ItemTable(items)
# or {{ table }} in jinja
print(table.__html__())
"""Outputs:
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name1</td>
<td>Description1</td>
</tr>
<tr>
<td>Name2</td>
<td>Description2</td>
</tr>
<tr>
<td>Name3</td>
<td>Description3</td>
</tr>
</tbody>
</table>
Except it doesn't bother to prettify the output.
"""
if __name__ == '__main__':
main()