Changeset 3824
- Timestamp:
- 12/15/07 08:50:16 (7 months ago)
- Files:
-
- branches/1.0/CHANGELOG.txt (modified) (4 diffs)
- branches/1.0/turbogears/paginate.py (modified) (2 diffs)
- branches/1.0/turbogears/tests/test_paginate.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0/CHANGELOG.txt
r3807 r3824 6 6 ------ 7 7 8 Changes 9 ~~~~~~~ 10 11 * Pagination can be disabled by using ``allow_limit_override`` and 12 ``tg_paginate_limit=0``, allowing all results been returned on one single 13 page (#1629). 14 8 15 Fixes 9 16 ~~~~~ 10 17 11 18 * Fixed VisitFilter when Identity is on and there are list parameters (#1622). 19 * Paginate does a better handling of zeroed limit, avoiding ZeroDivisionError 20 exception (#1629). 21 22 Contributors 23 ~~~~~~~~~~~~ 24 25 Toshio Kuratomi. 12 26 13 27 … … 18 32 ~~~~~~~~~~~~ 19 33 20 * Paginate ``default_order`` has been greatly improved. Use of the 34 * Paginate ``default_order`` has been greatly improved. Use of the 21 35 ``default_reversed`` parameter has been deprecated. It will still be used 22 36 if it is informed, but a DeprecationWarning will be displayed. … … 32 46 to compute the correct last page number at server-side (#1617). 33 47 * The ``start-<project>.py`` script in a quickstarted project is now only a 34 wrapper for the ``start()`` function in a new ``commands`` module in the 48 wrapper for the ``start()`` function in a new ``commands`` module in the 35 49 project's package. The ``setup.py`` in new project also creates a console 36 50 script entry point for this, so easy_install can create a start script … … 57 71 last page is requested, respectively. 58 72 * Paginate ``default_order`` can now be a string or a list of strings. 59 The list of string is used to specify the ordering of multiple columns.60 Every string starting with a dash (``-``) indicates that the column will 73 The list of strings is used to specify the ordering of multiple columns. 74 Every string starting with a dash (``-``) indicates that the column will 61 75 have its default ordering reversed (#1618). 62 * turbogears.url() allows to to create an url with multiple values for the 76 * turbogears.url() allows to to create an url with multiple values for the 63 77 same key (#1456). 64 78 branches/1.0/turbogears/paginate.py
r3744 r3824 161 161 else: 162 162 df = default_order 163 163 164 164 ordering = dict([(v.lstrip('-'), [k, not v.startswith('-')]) 165 165 for k,v in enumerate(df)]) … … 200 200 'Variable is not a list or SelectResults or Query (%s)' % type( 201 201 var_data)) 202 203 # If limit is zero then return all our rows 204 if not limit_: 205 limit_ = row_count or 1 202 206 203 207 page_count = int(ceil(float(row_count)/limit_)) branches/1.0/turbogears/tests/test_paginate.py
r3790 r3824 257 257 258 258 def empty(self): 259 spy = Spy(var_name='data', pages=[], limit=4,page_count=0,259 spy = Spy(var_name='data', pages=[], page_count=0, 260 260 order=None, ordering={}, row_count=0, 261 261 current_page=1, first_item=0, last_item=0) 262 262 data = [] 263 263 return dict(data=data, spy=spy) 264 empty = paginate("data", limit=4 )(empty)264 empty = paginate("data", limit=4, allow_limit_override=True)(empty) 265 265 empty = expose()(empty) 266 266 # end of MyRoot ------------------------------------------------------------ … … 401 401 for number in range(4, 7): 402 402 self.request("/basic/?tg_paginate_no=%s" % number) 403 print self.body404 403 assert '"data": [8, 9]' in self.body 405 404 Spy.assert_ok(self.body, 'current_page', 3) … … 409 408 def test_last_page(self): 410 409 self.request("/basic/?tg_paginate_no=last") 411 print self.body412 410 assert '"data": [8, 9]' in self.body 413 411 Spy.assert_ok(self.body, 'current_page', 3) … … 461 459 def test_empty_data(self): 462 460 self.request("/empty") 461 assert '"data": []' in self.body 462 Spy.assert_ok(self.body, 'limit', 4) 463 464 def test_zero_limit(self): 465 self.request("/custom_limit/?data_tgp_limit=0") 466 assert '"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]' in self.body 467 Spy.assert_ok(self.body, 'page_count', 1) 468 Spy.assert_ok(self.body, 'limit', 10) 469 Spy.assert_ok(self.body, 'pages', [1]) 470 471 def test_empty_data_zero_limit(self): 472 self.request("/empty/?data_tgp_limit=0") 463 473 print self.body 464 474 assert '"data": []' in self.body 475 Spy.assert_ok(self.body, 'page_count', 0) 476 Spy.assert_ok(self.body, 'limit', 1) 465 477 466 478 … … 590 602 related = expose("turbogears.tests.paginate")(related) 591 603 604 def zero_limit(self, method=None): 605 if method == "Q": 606 data = session.query(Address) 607 elif method == "SR": 608 data = SASelectResults(session.query(Address)) 609 elif method == "SO": 610 data = SOAddress.select() 611 else: 612 raise Exception("Invalid method") 613 614 spy = Spy(var_name='data', pages=[1], limit=16, page_count=1, 615 order=None, row_count=16) 616 return dict(data=data, spy=spy) 617 618 zero_limit = paginate("data", default_order="id", limit=0)(zero_limit) 619 zero_limit = expose("turbogears.tests.paginate")(zero_limit) 620 592 621 # end of MyRoot ------------------------------------------------------------ 593 622 … … 666 695 for method in "Q", "SR", "SO": 667 696 self.request("/wrong_reversed/?method=%s" % method) 668 print self.body669 697 assert 'StandardError: default_reversed (deprecated) is only allowed' in self.body 670 698 … … 862 890 self.assert_order(2, 14, 13, 10, 5, 1) 863 891 Spy.assert_ok(self.body, 'ordering', {'user.occupation.name': [0, False], 'id': [1, False]}) 892 893 def test_zero_limit(self): 894 for method in "Q", "SR", "SO": 895 self.request("/zero_limit/?method=%s" % method) 896 self.assert_order(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) 864 897 865 898