pyams-table 1.0.0__py3.5.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +55 -0
- EGG-INFO/SOURCES.txt +32 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/namespace_packages.txt +1 -0
- EGG-INFO/not-zip-safe +1 -0
- EGG-INFO/requires.txt +14 -0
- EGG-INFO/top_level.txt +1 -0
- pyams_table/__init__.py +29 -0
- pyams_table/__pycache__/__init__.cpython-35.pyc +0 -0
- pyams_table/__pycache__/batch.cpython-35.pyc +0 -0
- pyams_table/__pycache__/column.cpython-35.pyc +0 -0
- pyams_table/__pycache__/header.cpython-35.pyc +0 -0
- pyams_table/__pycache__/include.cpython-35.pyc +0 -0
- pyams_table/__pycache__/interfaces.cpython-35.pyc +0 -0
- pyams_table/__pycache__/table.cpython-35.pyc +0 -0
- pyams_table/__pycache__/testing.cpython-35.pyc +0 -0
- pyams_table/__pycache__/value.cpython-35.pyc +0 -0
- pyams_table/batch.py +159 -0
- pyams_table/column.py +495 -0
- pyams_table/doctests/README.rst +668 -0
- pyams_table/doctests/batch.rst +660 -0
- pyams_table/doctests/column.rst +1274 -0
- pyams_table/doctests/miscellaneous.rst +123 -0
- pyams_table/doctests/sequence.rst +267 -0
- pyams_table/doctests/sort.rst +388 -0
- pyams_table/header.py +102 -0
- pyams_table/include.py +27 -0
- pyams_table/interfaces.py +249 -0
- pyams_table/locales/fr/LC_MESSAGES/pyams_table.mo +0 -0
- pyams_table/locales/fr/LC_MESSAGES/pyams_table.po +40 -0
- pyams_table/locales/pyams_table.pot +41 -0
- pyams_table/table.py +383 -0
- pyams_table/testing.py +129 -0
- pyams_table/tests/__init__.py +29 -0
- pyams_table/tests/__pycache__/__init__.cpython-35.pyc +0 -0
- pyams_table/tests/__pycache__/test_utilsdocs.cpython-35.pyc +0 -0
- pyams_table/tests/__pycache__/test_utilsdocstrings.cpython-35.pyc +0 -0
- pyams_table/tests/test_utilsdocs.py +60 -0
- pyams_table/tests/test_utilsdocstrings.py +65 -0
- pyams_table/value.py +51 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Miscellaneous
|
|
2
|
+
-------------
|
|
3
|
+
|
|
4
|
+
Make coverage report happy and test different things.
|
|
5
|
+
|
|
6
|
+
>>> from pyramid.testing import setUp, tearDown, DummyRequest
|
|
7
|
+
>>> from pyams_table.testing import setup_adapters
|
|
8
|
+
|
|
9
|
+
>>> config = setUp()
|
|
10
|
+
>>> setup_adapters(config.registry)
|
|
11
|
+
>>> root = {}
|
|
12
|
+
|
|
13
|
+
Test if the getWeight method returns 0 (zero) on AttributeError:
|
|
14
|
+
|
|
15
|
+
>>> from pyams_table.table import get_weight
|
|
16
|
+
>>> get_weight(None)
|
|
17
|
+
0
|
|
18
|
+
|
|
19
|
+
Create a container:
|
|
20
|
+
|
|
21
|
+
>>> from pyams_table.testing import Container
|
|
22
|
+
>>> container = Container()
|
|
23
|
+
|
|
24
|
+
Try to call a simple table and call renderBatch which should return an empty
|
|
25
|
+
string:
|
|
26
|
+
|
|
27
|
+
>>> from pyams_table import table
|
|
28
|
+
>>> request = DummyRequest()
|
|
29
|
+
>>> simpleTable = table.Table(container, request)
|
|
30
|
+
>>> simpleTable.render_batch()
|
|
31
|
+
''
|
|
32
|
+
|
|
33
|
+
Try to render an empty table adapting an empty mapping:
|
|
34
|
+
|
|
35
|
+
>>> simpleTable = table.Table({}, request)
|
|
36
|
+
>>> simpleTable.css_class_sorted_on = None
|
|
37
|
+
>>> simpleTable.render()
|
|
38
|
+
''
|
|
39
|
+
|
|
40
|
+
Since we register an adapter for IColumn on None (IOW on an empty mapping).
|
|
41
|
+
|
|
42
|
+
>>> from zope.component import provideAdapter
|
|
43
|
+
>>> from pyams_table import column
|
|
44
|
+
>>> from pyams_table import interfaces
|
|
45
|
+
>>> config.registry.registerAdapter(column.NameColumn,
|
|
46
|
+
... (None, None, interfaces.ITable), provided=interfaces.IColumn,
|
|
47
|
+
... name='secondColumn')
|
|
48
|
+
|
|
49
|
+
Initializing rows definitions for the empty table initializes the columns
|
|
50
|
+
attribute list.
|
|
51
|
+
|
|
52
|
+
>>> simpleTable.columns
|
|
53
|
+
|
|
54
|
+
>>> simpleTable.init_columns()
|
|
55
|
+
>>> simpleTable.columns
|
|
56
|
+
[<NameColumn 'secondColumn'>]
|
|
57
|
+
|
|
58
|
+
Rendering the empty table now return the string:
|
|
59
|
+
|
|
60
|
+
>>> print(simpleTable.render())
|
|
61
|
+
<table>
|
|
62
|
+
<thead>
|
|
63
|
+
<tr>
|
|
64
|
+
<th>Name</th>
|
|
65
|
+
</tr>
|
|
66
|
+
</thead>
|
|
67
|
+
<tbody>
|
|
68
|
+
</tbody>
|
|
69
|
+
</table>
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
Let's see if the addColumn raises a ValueError if there is no Column class:
|
|
73
|
+
|
|
74
|
+
>>> column.add_column(simpleTable, column.Column, 'dummy')
|
|
75
|
+
<Column 'dummy'>
|
|
76
|
+
|
|
77
|
+
>>> column.add_column(simpleTable, None, 'dummy')
|
|
78
|
+
Traceback (most recent call last):
|
|
79
|
+
...
|
|
80
|
+
ValueError: class_ None must implement IColumn.
|
|
81
|
+
|
|
82
|
+
Test if we can set additional kws in addColumn:
|
|
83
|
+
|
|
84
|
+
>>> simpleColumn = column.add_column(simpleTable, column.Column, 'dummy',
|
|
85
|
+
... foo='foo value', bar='something else', counter=99)
|
|
86
|
+
>>> simpleColumn.foo
|
|
87
|
+
'foo value'
|
|
88
|
+
|
|
89
|
+
>>> simpleColumn.bar
|
|
90
|
+
'something else'
|
|
91
|
+
|
|
92
|
+
>>> simpleColumn.counter
|
|
93
|
+
99
|
|
94
|
+
|
|
95
|
+
The NoneCell class provides some methods which never get called. But these
|
|
96
|
+
are defined in the interface. Let's test the default values
|
|
97
|
+
and make coverage report happy.
|
|
98
|
+
|
|
99
|
+
Let's get an container item first:
|
|
100
|
+
|
|
101
|
+
>>> from pyams_table.testing import Content
|
|
102
|
+
>>> firstItem = Content('First', 1)
|
|
103
|
+
>>> noneCellColumn = column.add_column(simpleTable, column.NoneCell, 'none')
|
|
104
|
+
>>> noneCellColumn.render_cell(firstItem)
|
|
105
|
+
''
|
|
106
|
+
|
|
107
|
+
>>> noneCellColumn.get_colspan(firstItem)
|
|
108
|
+
0
|
|
109
|
+
|
|
110
|
+
>>> noneCellColumn.render_head_cell()
|
|
111
|
+
''
|
|
112
|
+
|
|
113
|
+
>>> noneCellColumn.render_cell(firstItem)
|
|
114
|
+
''
|
|
115
|
+
|
|
116
|
+
The default ``Column`` implementation raises an NotImplementedError if we
|
|
117
|
+
do not override the render_cell method:
|
|
118
|
+
|
|
119
|
+
>>> defaultColumn = column.add_column(simpleTable, column.Column, 'default')
|
|
120
|
+
>>> defaultColumn.render_cell(firstItem)
|
|
121
|
+
Traceback (most recent call last):
|
|
122
|
+
...
|
|
123
|
+
NotImplementedError: Subclass must implement render_cell
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
SequenceTable
|
|
2
|
+
-------------
|
|
3
|
+
|
|
4
|
+
A sequence table can be used if we need to provide a table for a sequence
|
|
5
|
+
of items instead of a mapping. Define the same sequence of items we used before
|
|
6
|
+
we added the other 1000 items:
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
>>> from pyramid.testing import setUp, tearDown, DummyRequest
|
|
10
|
+
>>> from pyams_table.testing import setup_adapters
|
|
11
|
+
|
|
12
|
+
>>> config = setUp()
|
|
13
|
+
>>> setup_adapters(config.registry)
|
|
14
|
+
>>> root = {}
|
|
15
|
+
|
|
16
|
+
>>> from pyams_table.testing import Content
|
|
17
|
+
>>> dataSequence = []
|
|
18
|
+
>>> dataSequence.append(Content('Zero', 0))
|
|
19
|
+
>>> dataSequence.append(Content('First', 1))
|
|
20
|
+
>>> dataSequence.append(Content('Second', 2))
|
|
21
|
+
>>> dataSequence.append(Content('Third', 3))
|
|
22
|
+
>>> dataSequence.append(Content('Fourth', 4))
|
|
23
|
+
>>> dataSequence.append(Content('Fifth', 5))
|
|
24
|
+
>>> dataSequence.append(Content('Sixth', 6))
|
|
25
|
+
>>> dataSequence.append(Content('Seventh', 7))
|
|
26
|
+
>>> dataSequence.append(Content('Eighth', 8))
|
|
27
|
+
>>> dataSequence.append(Content('Ninth', 9))
|
|
28
|
+
>>> dataSequence.append(Content('Tenth', 10))
|
|
29
|
+
>>> dataSequence.append(Content('Eleventh', 11))
|
|
30
|
+
>>> dataSequence.append(Content('Twelfth', 12))
|
|
31
|
+
>>> dataSequence.append(Content('Thirteenth', 13))
|
|
32
|
+
>>> dataSequence.append(Content('Fourteenth', 14))
|
|
33
|
+
>>> dataSequence.append(Content('Fifteenth', 15))
|
|
34
|
+
>>> dataSequence.append(Content('Sixteenth', 16))
|
|
35
|
+
>>> dataSequence.append(Content('Seventeenth', 17))
|
|
36
|
+
>>> dataSequence.append(Content('Eighteenth', 18))
|
|
37
|
+
>>> dataSequence.append(Content('Nineteenth', 19))
|
|
38
|
+
>>> dataSequence.append(Content('Twentieth', 20))
|
|
39
|
+
|
|
40
|
+
Now let's define a new SequenceTable:
|
|
41
|
+
|
|
42
|
+
>>> from pyams_table import table, column
|
|
43
|
+
>>> from pyams_table.testing import (TitleColumn, NumberColumn, cell_renderer,
|
|
44
|
+
... head_cell_renderer)
|
|
45
|
+
>>> class SequenceTable(table.SequenceTable):
|
|
46
|
+
...
|
|
47
|
+
... def setup_columns(self):
|
|
48
|
+
... return [
|
|
49
|
+
... column.add_column(self, TitleColumn, 'title',
|
|
50
|
+
... cell_renderer=cell_renderer,
|
|
51
|
+
... head_cell_renderer=head_cell_renderer,
|
|
52
|
+
... weight=1),
|
|
53
|
+
... column.add_column(self, NumberColumn, name='number',
|
|
54
|
+
... weight=2, header='Number')
|
|
55
|
+
... ]
|
|
56
|
+
|
|
57
|
+
Now we can create our table adapting our sequence:
|
|
58
|
+
|
|
59
|
+
>>> sequenceRequest = DummyRequest(params={'table-batch-start': '0',
|
|
60
|
+
... 'table-sort-on': 'table-number-1'})
|
|
61
|
+
>>> sequenceTable = SequenceTable(dataSequence, sequenceRequest)
|
|
62
|
+
>>> sequenceTable.css_class_sorted_on = None
|
|
63
|
+
|
|
64
|
+
We also need to give the table a location and a name like we normally setup
|
|
65
|
+
in traversing:
|
|
66
|
+
|
|
67
|
+
>>> from pyams_table.testing import Container
|
|
68
|
+
>>> container = Container()
|
|
69
|
+
>>> root['container-1'] = container
|
|
70
|
+
>>> sequenceTable.__parent__ = container
|
|
71
|
+
>>> sequenceTable.__name__ = 'sequenceTable.html'
|
|
72
|
+
|
|
73
|
+
We need to configure our batch provider for the next step first. See the
|
|
74
|
+
section ``BatchProvider`` below for more infos about batch rendering:
|
|
75
|
+
|
|
76
|
+
>>> from zope.interface import Interface
|
|
77
|
+
>>> from pyramid.interfaces import IRequest
|
|
78
|
+
>>> from pyams_batching.interfaces import IBatch
|
|
79
|
+
>>> from pyams_batching.batch import Batch
|
|
80
|
+
>>> from pyams_table.interfaces import IBatchProvider, ITable
|
|
81
|
+
>>> from pyams_table.batch import BatchProvider
|
|
82
|
+
>>> from pyams_utils.factory import register_factory
|
|
83
|
+
>>> register_factory(IBatch, Batch)
|
|
84
|
+
>>> config.registry.registerAdapter(BatchProvider,
|
|
85
|
+
... (Interface, IRequest, ITable),
|
|
86
|
+
... provided=IBatchProvider,
|
|
87
|
+
... name='batch')
|
|
88
|
+
|
|
89
|
+
And update and render the sequence table:
|
|
90
|
+
|
|
91
|
+
>>> sequenceTable.update()
|
|
92
|
+
>>> print(sequenceTable.render())
|
|
93
|
+
<table>
|
|
94
|
+
<thead>
|
|
95
|
+
<tr>
|
|
96
|
+
<th>My items</th>
|
|
97
|
+
<th>Number</th>
|
|
98
|
+
</tr>
|
|
99
|
+
</thead>
|
|
100
|
+
<tbody>
|
|
101
|
+
<tr>
|
|
102
|
+
<td>Zero item</td>
|
|
103
|
+
<td>number: 0</td>
|
|
104
|
+
</tr>
|
|
105
|
+
<tr>
|
|
106
|
+
<td>First item</td>
|
|
107
|
+
<td>number: 1</td>
|
|
108
|
+
</tr>
|
|
109
|
+
<tr>
|
|
110
|
+
<td>Second item</td>
|
|
111
|
+
<td>number: 2</td>
|
|
112
|
+
</tr>
|
|
113
|
+
<tr>
|
|
114
|
+
<td>Third item</td>
|
|
115
|
+
<td>number: 3</td>
|
|
116
|
+
</tr>
|
|
117
|
+
<tr>
|
|
118
|
+
<td>Fourth item</td>
|
|
119
|
+
<td>number: 4</td>
|
|
120
|
+
</tr>
|
|
121
|
+
<tr>
|
|
122
|
+
<td>Fifth item</td>
|
|
123
|
+
<td>number: 5</td>
|
|
124
|
+
</tr>
|
|
125
|
+
<tr>
|
|
126
|
+
<td>Sixth item</td>
|
|
127
|
+
<td>number: 6</td>
|
|
128
|
+
</tr>
|
|
129
|
+
<tr>
|
|
130
|
+
<td>Seventh item</td>
|
|
131
|
+
<td>number: 7</td>
|
|
132
|
+
</tr>
|
|
133
|
+
<tr>
|
|
134
|
+
<td>Eighth item</td>
|
|
135
|
+
<td>number: 8</td>
|
|
136
|
+
</tr>
|
|
137
|
+
<tr>
|
|
138
|
+
<td>Ninth item</td>
|
|
139
|
+
<td>number: 9</td>
|
|
140
|
+
</tr>
|
|
141
|
+
<tr>
|
|
142
|
+
<td>Tenth item</td>
|
|
143
|
+
<td>number: 10</td>
|
|
144
|
+
</tr>
|
|
145
|
+
<tr>
|
|
146
|
+
<td>Eleventh item</td>
|
|
147
|
+
<td>number: 11</td>
|
|
148
|
+
</tr>
|
|
149
|
+
<tr>
|
|
150
|
+
<td>Twelfth item</td>
|
|
151
|
+
<td>number: 12</td>
|
|
152
|
+
</tr>
|
|
153
|
+
<tr>
|
|
154
|
+
<td>Thirteenth item</td>
|
|
155
|
+
<td>number: 13</td>
|
|
156
|
+
</tr>
|
|
157
|
+
<tr>
|
|
158
|
+
<td>Fourteenth item</td>
|
|
159
|
+
<td>number: 14</td>
|
|
160
|
+
</tr>
|
|
161
|
+
<tr>
|
|
162
|
+
<td>Fifteenth item</td>
|
|
163
|
+
<td>number: 15</td>
|
|
164
|
+
</tr>
|
|
165
|
+
<tr>
|
|
166
|
+
<td>Sixteenth item</td>
|
|
167
|
+
<td>number: 16</td>
|
|
168
|
+
</tr>
|
|
169
|
+
<tr>
|
|
170
|
+
<td>Seventeenth item</td>
|
|
171
|
+
<td>number: 17</td>
|
|
172
|
+
</tr>
|
|
173
|
+
<tr>
|
|
174
|
+
<td>Eighteenth item</td>
|
|
175
|
+
<td>number: 18</td>
|
|
176
|
+
</tr>
|
|
177
|
+
<tr>
|
|
178
|
+
<td>Nineteenth item</td>
|
|
179
|
+
<td>number: 19</td>
|
|
180
|
+
</tr>
|
|
181
|
+
<tr>
|
|
182
|
+
<td>Twentieth item</td>
|
|
183
|
+
<td>number: 20</td>
|
|
184
|
+
</tr>
|
|
185
|
+
</tbody>
|
|
186
|
+
</table>
|
|
187
|
+
|
|
188
|
+
As you can see, the items get rendered based on a data sequence. Now we set
|
|
189
|
+
the ``start batch at`` size to ``5``:
|
|
190
|
+
|
|
191
|
+
>>> sequenceTable.start_batching_at = 5
|
|
192
|
+
|
|
193
|
+
And the ``batch_size`` to ``5``:
|
|
194
|
+
|
|
195
|
+
>>> sequenceTable.batch_size = 5
|
|
196
|
+
|
|
197
|
+
Now we can update and render the table again. But you will see that we only get
|
|
198
|
+
a table size of 5 rows:
|
|
199
|
+
|
|
200
|
+
>>> sequenceTable.update()
|
|
201
|
+
>>> print(sequenceTable.render())
|
|
202
|
+
<table>
|
|
203
|
+
<thead>
|
|
204
|
+
<tr>
|
|
205
|
+
<th>My items</th>
|
|
206
|
+
<th>Number</th>
|
|
207
|
+
</tr>
|
|
208
|
+
</thead>
|
|
209
|
+
<tbody>
|
|
210
|
+
<tr>
|
|
211
|
+
<td>Zero item</td>
|
|
212
|
+
<td>number: 0</td>
|
|
213
|
+
</tr>
|
|
214
|
+
<tr>
|
|
215
|
+
<td>First item</td>
|
|
216
|
+
<td>number: 1</td>
|
|
217
|
+
</tr>
|
|
218
|
+
<tr>
|
|
219
|
+
<td>Second item</td>
|
|
220
|
+
<td>number: 2</td>
|
|
221
|
+
</tr>
|
|
222
|
+
<tr>
|
|
223
|
+
<td>Third item</td>
|
|
224
|
+
<td>number: 3</td>
|
|
225
|
+
</tr>
|
|
226
|
+
<tr>
|
|
227
|
+
<td>Fourth item</td>
|
|
228
|
+
<td>number: 4</td>
|
|
229
|
+
</tr>
|
|
230
|
+
</tbody>
|
|
231
|
+
</table>
|
|
232
|
+
|
|
233
|
+
And we set the sort order to ``reverse`` even if we use batching:
|
|
234
|
+
|
|
235
|
+
>>> sequenceTable.sort_order = 'reverse'
|
|
236
|
+
>>> sequenceTable.update()
|
|
237
|
+
>>> print(sequenceTable.render())
|
|
238
|
+
<table>
|
|
239
|
+
<thead>
|
|
240
|
+
<tr>
|
|
241
|
+
<th>My items</th>
|
|
242
|
+
<th>Number</th>
|
|
243
|
+
</tr>
|
|
244
|
+
</thead>
|
|
245
|
+
<tbody>
|
|
246
|
+
<tr>
|
|
247
|
+
<td>Twentieth item</td>
|
|
248
|
+
<td>number: 20</td>
|
|
249
|
+
</tr>
|
|
250
|
+
<tr>
|
|
251
|
+
<td>Nineteenth item</td>
|
|
252
|
+
<td>number: 19</td>
|
|
253
|
+
</tr>
|
|
254
|
+
<tr>
|
|
255
|
+
<td>Eighteenth item</td>
|
|
256
|
+
<td>number: 18</td>
|
|
257
|
+
</tr>
|
|
258
|
+
<tr>
|
|
259
|
+
<td>Seventeenth item</td>
|
|
260
|
+
<td>number: 17</td>
|
|
261
|
+
</tr>
|
|
262
|
+
<tr>
|
|
263
|
+
<td>Sixteenth item</td>
|
|
264
|
+
<td>number: 16</td>
|
|
265
|
+
</tr>
|
|
266
|
+
</tbody>
|
|
267
|
+
</table>
|