From: Radek Czajka Date: Sun, 4 Aug 2019 18:49:41 +0000 (+0200) Subject: Fixes for Django up to 2.2 X-Git-Tag: 2.2.3 X-Git-Url: https://git.mdrn.pl/django-pagination.git/commitdiff_plain/c32098c13826bb1b6f3781bfae7080d3fe9e03ff?ds=inline Fixes for Django up to 2.2 --- diff --git a/.gitignore b/.gitignore index b0074fd..c2803e4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ test.db build dist .idea/ +.coverage +.eggs +.tox diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6f9a195..0000000 --- a/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -language: python -python: - - "2.7" - - "3.2" - - "3.3" - - "3.4" - - "3.5" -env: - matrix: - - DJANGO_VERSION=1.2 - - DJANGO_VERSION=1.3 - - DJANGO_VERSION=1.4 - - DJANGO_VERSION=1.5 - - DJANGO_VERSION=1.6 - - DJANGO_VERSION=1.7 - - DJANGO_VERSION=1.8 - - DJANGO_VERSION=1.9 -install: - - pip install 'coverage<4' # coverage>=4 has issues with python3 - - pip install -q Django==$DJANGO_VERSION coveralls - - python setup.py egg_info -script: coverage run --source='fnp_django_pagination' --omit *runner*,*test_project* setup.py test -after_success: - - coveralls -matrix: - include: - - python: "2.6" - env: DJANGO_VERSION=1.4 - - python: "2.6" - env: DJANGO_VERSION=1.5 - - python: "2.6" - env: DJANGO_VERSION=1.6 - exclude: - - python: "3.2" - env: DJANGO_VERSION=1.2 # Unsupported - - python: "3.2" - env: DJANGO_VERSION=1.3 # Unsupported - - python: "3.2" - env: DJANGO_VERSION=1.4 # Unsupported - - python: "3.2" - env: DJANGO_VERSION=1.9 # Unsupported - - python: "3.3" - env: DJANGO_VERSION=1.9 # ImportError: cannot import name find_spec - - python: "3.3" - env: DJANGO_VERSION=1.2 # Unsupported - - python: "3.3" - env: DJANGO_VERSION=1.3 # Unsupported - - python: "3.3" - env: DJANGO_VERSION=1.4 # Unsupported - - python: "3.4" - env: DJANGO_VERSION=1.2 # Unsupported - - python: "3.4" - env: DJANGO_VERSION=1.3 # Unsupported - - python: "3.4" - env: DJANGO_VERSION=1.4 # Unsupported - - python: "3.5" - env: DJANGO_VERSION=1.2 # Unsupported - - python: "3.5" - env: DJANGO_VERSION=1.3 # Unsupported - - python: "3.5" - env: DJANGO_VERSION=1.4 # Unsupported - - python: "3.5" - env: DJANGO_VERSION=1.5 # Unsupported - - python: "3.5" - env: DJANGO_VERSION=1.7 # AttributeError: module 'html.parser' has no attribute 'HTMLParseError' - - python: "3.5" - env: DJANGO_VERSION=1.6 # AttributeError: module 'html.parser' has no attribute 'HTMLParseError' diff --git a/fnp_django_pagination/__init__.py b/fnp_django_pagination/__init__.py index c6e0cfa..ec778ac 100644 --- a/fnp_django_pagination/__init__.py +++ b/fnp_django_pagination/__init__.py @@ -34,4 +34,4 @@ tools throughout a django application. """ -__version__ = (2, 2, 2, "final", 0) +__version__ = (2, 2, 3, "final", 0) diff --git a/fnp_django_pagination/middleware.py b/fnp_django_pagination/middleware.py index 580be43..02f8e7c 100644 --- a/fnp_django_pagination/middleware.py +++ b/fnp_django_pagination/middleware.py @@ -28,6 +28,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from django.utils.deprecation import MiddlewareMixin + def get_page(self, suffix): """ @@ -45,7 +47,7 @@ def get_page(self, suffix): return 1 -class PaginationMiddleware(object): +class PaginationMiddleware(MiddlewareMixin): """ Inserts a variable representing the current page onto the request object if it exists in either **GET** or **POST** portions of the request. diff --git a/fnp_django_pagination/paginator.py b/fnp_django_pagination/paginator.py index cd3a0f7..d5bf2d2 100644 --- a/fnp_django_pagination/paginator.py +++ b/fnp_django_pagination/paginator.py @@ -48,7 +48,11 @@ class InfinitePaginator(Paginator): super(InfinitePaginator, self).__init__(object_list, per_page, orphans, allow_empty_first_page) # no count or num pages - del self._num_pages, self._count + try: + del self._num_pages, self._count + except AttributeError: + # These are just cached properties anyway. + pass # bonus links self.link_template = link_template diff --git a/fnp_django_pagination/templatetags/pagination_tags.py b/fnp_django_pagination/templatetags/pagination_tags.py index 7f38da5..3802a47 100644 --- a/fnp_django_pagination/templatetags/pagination_tags.py +++ b/fnp_django_pagination/templatetags/pagination_tags.py @@ -43,9 +43,14 @@ from django.template import ( ) try: - from django.template.base import TOKEN_BLOCK -except ImportError: # Django < 1.8 - from django.template import TOKEN_BLOCK + from django.template.base import TokenType + TOKEN_BLOCK = TokenType.BLOCK +except ImportError: + try: + # Django 1.8-1.11 + from django.template.base import TOKEN_BLOCK + except ImportError: # Django < 1.8 + from django.template import TOKEN_BLOCK from django.template.loader import select_template from django.utils.text import unescape_string_literal diff --git a/fnp_django_pagination/tests/settings.py b/fnp_django_pagination/tests/settings.py index 10243b8..d320df8 100644 --- a/fnp_django_pagination/tests/settings.py +++ b/fnp_django_pagination/tests/settings.py @@ -10,3 +10,10 @@ SECRET_KEY = 'fake-key' INSTALLED_APPS = ( 'fnp_django_pagination', ) + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + }, +] diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ff4bdfa --- /dev/null +++ b/tox.ini @@ -0,0 +1,42 @@ +# This file is part of django-ssify, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See README.md for more information. +# +[tox] +envlist=clear, + d{12,13,14}-py27, + d{15}-py{27,32}, + d16-py{27,32,33}, + d17-py{27,32,33,34}, + d18-py{27,32,33,34}, + d{19,110}-py{27,34,35}, + d111-py{27,34,35,36,37}, + d20-py{34,35,36,37}, + d{21,22}-py{35,36,37}, + stats + +[testenv] +indexserver=https://py.mdrn.pl:8443 +commands=coverage run --source=fnp_django_pagination --omit *runner*,*test_project* setup.py test +deps= + d12: Django>=1.2,<1.3 + d13: Django>=1.3,<1.4 + d14: Django>=1.4,<1.5 + d15: Django>=1.5,<1.6 + d16: Django>=1.6,<1.7 + d17: Django>=1.7,<1.8 + d18: Django>=1.8,<1.9 + d19: Django>=1.9,<1.10 + d110: Django>=1.10,<1.11 + d111: Django>=1.11,<2.0 + d20: Django>=2.0,<2.1 + d21: Django>=2.1,<2.2 + d22: Django>=2.2,<2.3 + coverage + +[testenv:clear] +basepython=python3.4 +commands=coverage erase + +[testenv:stats] +basepython=python3.4 +commands=coverage html