Projet

Général

Profil

0001-misc-be-sure-that-pagination-is-not-too-high-49422.patch

Lauréline Guérin, 17 décembre 2020 11:23

Télécharger (2,53 ko)

Voir les différences:

Subject: [PATCH] misc: be sure that pagination is not too high (#49422)

 tests/test_misc.py               | 16 ++++++++++++++++
 wcs/qommon/backoffice/listing.py |  8 ++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
tests/test_misc.py
310 310
    assert get_texts(pagination_links(100, 20, 500)) == [
311 311
            '1', '…', '3', '4', '5', '6', '7', '8', '9', '…', '25', '(101-120/500)', 'Per page: ', '10', '20', '50', '100']
312 312

  
313
    # check limit
314
    assert '(1-10/1000)' in get_texts(pagination_links(0, 10, 1000))
315
    assert '(1-100/1000)' in get_texts(pagination_links(0, 100, 1000))
316
    assert '(1-100/1000)' in get_texts(pagination_links(0, 101, 1000))  # 100 is the max
317

  
318
    # new default pagination, more than 100
319
    if not pub.site_options.has_section('options'):
320
        pub.site_options.add_section('options')
321
    pub.site_options.set('options', 'default-page-size', '500')
322
    fd = open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w')
323
    pub.site_options.write(fd)
324
    fd.close()
325
    assert '(1-101/1000)' in get_texts(pagination_links(0, 101, 1000))
326
    assert '(1-500/1000)' in get_texts(pagination_links(0, 500, 1000))
327
    assert '(1-500/1000)' in get_texts(pagination_links(0, 501, 1000))  # 500 is the max
328

  
313 329

  
314 330
def test_email_signature_plain(emails):
315 331
    pub = create_temporary_pub()
wcs/qommon/backoffice/listing.py
16 16

  
17 17
from django.utils.six.moves.urllib import parse as urllib
18 18
from quixote.html import htmltext, TemplateIO
19
from quixote import get_request, get_response
19
from quixote import get_request, get_response, get_publisher
20 20

  
21 21
from .. import _
22 22

  
23 23

  
24 24
def pagination_links(offset, limit, total_count):
25
    limit = limit or 10  # make sure a limit is set
25
    # make sure a limit is set
26
    limit = limit or 10
27
    # make sure limit is not too high
28
    default_limit = int(get_publisher().get_site_option('default-page-size') or 20)
29
    limit = min(limit, max(100, default_limit))
26 30
    get_response().add_javascript(['wcs.listing.js'])
27 31
    # pagination
28 32
    r = TemplateIO(html=True)
29
-