Changeset 3824

Show
Ignore:
Timestamp:
12/15/07 08:50:16 (7 months ago)
Author:
roger
Message:

fix #1629

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/CHANGELOG.txt

    r3807 r3824  
    66------ 
    77 
     8Changes 
     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 
    815Fixes 
    916~~~~~ 
    1017 
    1118* 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 
     22Contributors 
     23~~~~~~~~~~~~ 
     24 
     25Toshio Kuratomi. 
    1226 
    1327 
     
    1832~~~~~~~~~~~~ 
    1933 
    20 * Paginate ``default_order`` has been greatly improved. Use of the  
     34* Paginate ``default_order`` has been greatly improved. Use of the 
    2135  ``default_reversed`` parameter has been deprecated. It will still be used 
    2236  if it is informed, but a DeprecationWarning will be displayed. 
     
    3246  to compute the correct last page number at server-side (#1617). 
    3347* 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 
    3549  project's package. The ``setup.py`` in new project also creates a console 
    3650  script entry point for this, so easy_install can create a start script 
     
    5771  last page is requested, respectively. 
    5872* 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 
    6175  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 
    6377  same key (#1456). 
    6478 
  • branches/1.0/turbogears/paginate.py

    r3744 r3824  
    161161                else: 
    162162                    df = default_order 
    163                          
     163 
    164164                ordering = dict([(v.lstrip('-'), [k, not v.startswith('-')]) 
    165165                                 for k,v in enumerate(df)]) 
     
    200200                    'Variable is not a list or SelectResults or Query (%s)' % type( 
    201201                            var_data)) 
     202 
     203            # If limit is zero then return all our rows 
     204            if not limit_: 
     205                limit_ = row_count or 1 
    202206 
    203207            page_count = int(ceil(float(row_count)/limit_)) 
  • branches/1.0/turbogears/tests/test_paginate.py

    r3790 r3824  
    257257 
    258258        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, 
    260260                      order=None, ordering={}, row_count=0, 
    261261                      current_page=1, first_item=0, last_item=0) 
    262262            data = [] 
    263263            return dict(data=data, spy=spy) 
    264         empty = paginate("data", limit=4)(empty) 
     264        empty = paginate("data", limit=4, allow_limit_override=True)(empty) 
    265265        empty = expose()(empty) 
    266266    # end of MyRoot ------------------------------------------------------------ 
     
    401401        for number in range(4, 7): 
    402402            self.request("/basic/?tg_paginate_no=%s" % number) 
    403             print self.body 
    404403            assert '"data": [8, 9]' in self.body 
    405404            Spy.assert_ok(self.body, 'current_page', 3) 
     
    409408    def test_last_page(self): 
    410409        self.request("/basic/?tg_paginate_no=last") 
    411         print self.body 
    412410        assert '"data": [8, 9]' in self.body 
    413411        Spy.assert_ok(self.body, 'current_page', 3) 
     
    461459    def test_empty_data(self): 
    462460        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") 
    463473        print self.body 
    464474        assert '"data": []' in self.body 
     475        Spy.assert_ok(self.body, 'page_count', 0) 
     476        Spy.assert_ok(self.body, 'limit', 1) 
    465477 
    466478 
     
    590602        related = expose("turbogears.tests.paginate")(related) 
    591603 
     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 
    592621    # end of MyRoot ------------------------------------------------------------ 
    593622 
     
    666695        for method in "Q", "SR", "SO": 
    667696            self.request("/wrong_reversed/?method=%s" % method) 
    668             print self.body 
    669697            assert 'StandardError: default_reversed (deprecated) is only  allowed' in self.body 
    670698 
     
    862890        self.assert_order(2, 14, 13, 10, 5, 1) 
    863891        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) 
    864897 
    865898