From: floguy Date: Fri, 30 May 2008 04:35:24 +0000 (+0000) Subject: Added test suite, and prevented pagination if the elusion would take up only one... X-Git-Tag: 1.0.6~44 X-Git-Url: https://git.mdrn.pl/django-pagination.git/commitdiff_plain/a35ff9bd925bb5fd3ab2e43cae19a62afb2f5701?ds=inline;hp=4d9362dc29cdd664d9b12f8f7a5e7acc0afac531 Added test suite, and prevented pagination if the elusion would take up only one space. git-svn-id: https://django-pagination.googlecode.com/svn/trunk@13 7f1efe38-554e-0410-b69d-834cb44da2d5 --- diff --git a/pagination/templatetags/pagination_tags.py b/pagination/templatetags/pagination_tags.py index bba21b8..e688b05 100644 --- a/pagination/templatetags/pagination_tags.py +++ b/pagination/templatetags/pagination_tags.py @@ -92,14 +92,24 @@ def paginate(context, window=4): first_list = sorted(list(first)) second_list = sorted(list(current)) pages.extend(first_list) - if first_list[-1] + 1 != second_list[0]: + diff = second_list[0] - first_list[-1] + if diff == 2: + pages.append(second_list[0] - 1) + elif diff == 1: + pass + else: pages.append(None) pages.extend(second_list) else: pages.extend(sorted(list(first.union(current)))) if len(current.intersection(last)) == 0: second_list = sorted(list(last)) - if pages[-1] + 1 != second_list[0]: + diff = second_list[0] - pages[-1] + if diff == 2: + pages.append(second_list[0] - 1) + elif diff == 1: + pass + else: pages.append(None) pages.extend(second_list) else: @@ -113,4 +123,4 @@ def paginate(context, window=4): except KeyError: return u'' register.inclusion_tag('pagination/pagination.html', takes_context=True)(paginate) -register.tag('autopaginate', do_autopaginate) +register.tag('autopaginate', do_autopaginate) \ No newline at end of file diff --git a/pagination/tests.py b/pagination/tests.py new file mode 100644 index 0000000..21aa350 --- /dev/null +++ b/pagination/tests.py @@ -0,0 +1,20 @@ +""" +>>> from django.core.paginator import Paginator +>>> from pagination.templatetags.pagination_tags import paginate + +>>> p = Paginator(range(15), 2) +>>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages'] +[1, 2, 3, 4, 5, 6, 7, 8] + +>>> p = Paginator(range(17), 2) +>>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages'] +[1, 2, 3, 4, 5, 6, 7, 8, 9] + +>>> p = Paginator(range(19), 2) +>>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages'] +[1, 2, 3, 4, None, 7, 8, 9, 10] + +>>> p = Paginator(range(21), 2) +>>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages'] +[1, 2, 3, 4, None, 8, 9, 10, 11] +""" \ No newline at end of file diff --git a/tests/runtests.py b/tests/runtests.py new file mode 100644 index 0000000..6fb4b93 --- /dev/null +++ b/tests/runtests.py @@ -0,0 +1,16 @@ +import sys +sys.path.append('..') + +import os +# Make a backup of DJANGO_SETTINGS_MODULE environment variable to restore later. +backup = os.environ.get('DJANGO_SETTINGS_MODULE', '') +os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' + +from django.test.simple import run_tests + +if __name__ == "__main__": + failures = run_tests(['pagination',], verbosity=9) + if failures: + sys.exit(failures) + # Reset the DJANGO_SETTINGS_MODULE to what it was before running tests. + os.environ['DJANGO_SETTINGS_MODULE'] = backup diff --git a/tests/settings.py b/tests/settings.py new file mode 100644 index 0000000..ede4087 --- /dev/null +++ b/tests/settings.py @@ -0,0 +1,6 @@ +DATABASE_ENGINE = 'sqlite3' +ROOT_URLCONF = '' +SITE_ID = 1 +INSTALLED_APPS = ( + 'pagination', +)