From 68de9711398a05e8cba24e57f404cf11a52b1727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 19 Feb 2020 19:23:28 +0000 Subject: [PATCH] Fix imports for Django >=3.0 Fixes #60 --- .travis.yml | 18 ++++++++++-- Dockerfile | 4 +-- .../django_bootstrap_breadcrumbs.py | 6 +++- tests/urls.py | 28 ++++++++++--------- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4c4db36..eedb036 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,15 +12,27 @@ python: env: matrix: - - DJANGO=2.0.7 + - DJANGO=3.0.3 + - DJANGO=2.2.10 + - DJANGO=2.0.13 - DJANGO=1.8.19 - DJANGO=1.10.8 - - DJANGO=1.11.14 + - DJANGO=1.11.28 matrix: exclude: - python: "2.7" - env: DJANGO=2.0.7 + env: DJANGO=2.0.13 + - python: "2.7" + env: DJANGO=2.2.10 + - python: "2.7" + env: DJANGO=3.0.3 + - python: "3.4" + env: DJANGO=2.2.10 + - python: "3.4" + env: DJANGO=3.0.3 + - python: "3.5" + env: DJANGO=3.0.3 - python: "3.6" env: DJANGO=1.8.19 - python: "3.6" diff --git a/Dockerfile b/Dockerfile index aa4ca01..1c86820 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM debian:jessie +FROM debian:stable LABEL maintainer "Ɓukasz Mierzwa " -RUN apt-get update && apt-get install --no-install-recommends -y python3-dev python3-pip libyaml-dev git \ +RUN apt-get update && apt-get install --no-install-recommends -y python3-dev python3-pip python3-setuptools libyaml-dev git \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/django_bootstrap_breadcrumbs/templatetags/django_bootstrap_breadcrumbs.py b/django_bootstrap_breadcrumbs/templatetags/django_bootstrap_breadcrumbs.py index 8e98ce0..0e98c65 100644 --- a/django_bootstrap_breadcrumbs/templatetags/django_bootstrap_breadcrumbs.py +++ b/django_bootstrap_breadcrumbs/templatetags/django_bootstrap_breadcrumbs.py @@ -13,12 +13,16 @@ from django.utils.html import escape from django.utils.safestring import mark_safe from django.utils.encoding import smart_text -from django.utils.translation import ugettext as _ from django.db.models import Model from django.conf import settings from django import template, VERSION from six import wraps +if VERSION >= (3, 0): + from django.utils.translation import gettext as _ +else: + from django.utils.translation import ugettext as _ + if VERSION >= (2, 0): from django.urls import (reverse, resolve, NoReverseMatch, Resolver404) else: diff --git a/tests/urls.py b/tests/urls.py index 620f42f..955fbbb 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -7,9 +7,14 @@ from __future__ import unicode_literals -import django.contrib.auth.views + from django import VERSION +if VERSION >= (2, 1): + from django.contrib.auth.views import LoginView + login = LoginView.as_view() +else: + from django.contrib.auth.views import login if VERSION < (1, 8): # pragma: nocover from django.conf.urls import url, include, patterns @@ -31,28 +36,25 @@ elif VERSION < (2, 0): from django.conf.urls import url, include nsurlpatters = [ - url(r'^login2$', django.contrib.auth.views.login, name='login2_url'), + url(r'^login2$', login, name='login2_url'), ] urlpatterns = [ - url(r'^login$', django.contrib.auth.views.login, name='login_url'), - url(r'^login/(?P[-_\w]+)$', django.contrib.auth.views.login, - name='login_args_url'), - url(r'^login/user/(?P\S+)$', django.contrib.auth.views.login, - name='login_kwargs_url'), + url(r'^login$', login, name='login_url'), + url(r'^login/(?P[-_\w]+)$', login, name='login_args_url'), + url(r'^login/user/(?P\S+)$', login, name='login_kwargs_url'), url(r'^ns/', include(nsurlpatters, namespace='ns')), ] else: from django.urls import include, path, re_path nsurlpatters = [ - path('login2', django.contrib.auth.views.login, name='login2_url'), + path('login2', login, name='login2_url'), ] urlpatterns = [ - path('login', django.contrib.auth.views.login, name='login_url'), - re_path(r'^login/(?P[-_\w]+)$', django.contrib.auth.views.login, - name='login_args_url'), - re_path(r'^login/user/(?P\S+)$', - django.contrib.auth.views.login, name='login_kwargs_url'), + path('login', login, name='login_url'), + re_path(r'^login/(?P[-_\w]+)$', login, name='login_args_url'), + re_path(r'^login/user/(?P\S+)$', login, + name='login_kwargs_url'), path('ns/', include((nsurlpatters, 'ns'), namespace='ns')), ]