Skip to content

Commit

Permalink
Remove Django 1.7, 1.8, 1.9, 1.10 compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed Aug 27, 2018
1 parent 10479b0 commit 4166a60
Show file tree
Hide file tree
Showing 29 changed files with 148 additions and 535 deletions.
14 changes: 0 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,14 @@ python:
- '3.4'
- '3.6'
env:
- DJANGO="django>=1.7.0,<1.8.0"
- DJANGO="django>=1.8.0,<1.9.0"
- DJANGO="django>=1.9.0,<1.10.0"
- DJANGO="django>=1.10.1,<1.11.0"
- DJANGO="django>=1.11.0,<1.12.0"
- DJANGO="django>=2.0,<2.1"
matrix:
exclude:
- python: '3.3'
env: DJANGO="django>=1.9.0,<1.10.0"
- python: '3.3'
env: DJANGO="django>=1.10.1,<1.11.0"
- python: '3.3'
env: DJANGO="django>=1.11.0,<1.12.0"
- python: '3.3'
env: DJANGO="django>=2.0,<2.1"
- python: '3.6'
env: DJANGO="django>=1.7.0,<1.8.0"
- python: '3.6'
env: DJANGO="django>=1.8.0,<1.9.0"
- python: '3.6'
env: DJANGO="django>=1.9.0,<1.10.0"
- python: '2.7'
env: DJANGO="django>=2.0,<2.1"
before_install:
Expand Down
10 changes: 4 additions & 6 deletions docs/advanced/migrating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ First create the translatable fields::
name=models.CharField(max_length=123),
)

Now create the migration:
Now create the migration::

* For Django 1.7, use: ``manage.py makemigrations myapp "add_translation_model"``
* For Django 1.8 and above, use: ``manage.py makemigrations myapp --name "add_translation_model"``
manage.py makemigrations myapp --name "add_translation_model"


Step 2: Copy the data
Expand Down Expand Up @@ -115,10 +114,9 @@ The example model now looks like::
name=models.CharField(max_length=123),
)

Create the database migration, it will simply remove the original field.
Create the database migration, it will simply remove the original field::

* For Django 1.7, use: ``manage.py makemigrations myapp "remove_untranslated_fields"``
* For Django 1.8 and above, use: ``manage.py makemigrations myapp --name "remove_untranslated_fields"``
manage.py makemigrations myapp --name "remove_untranslated_fields"


Updating code
Expand Down
20 changes: 4 additions & 16 deletions docs/advanced/mptt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,19 @@ Say we have a base ``Category`` model that needs to be translatable:
Combining managers
------------------

The managers can be combined by inheriting them.
Unfortunately, django-mptt_ 0.7 overrides the ``get_queryset()`` method,
so it needs to be redefined:
The managers can be combined by inheriting them:

.. code-block:: python
import django
from parler.managers import TranslatableManager, TranslatableQuerySet
from mptt.managers import TreeManager
from mptt.querysets import TreeQuerySet # new as of mptt 0.7
from mptt.querysets import TreeQuerySet
class CategoryQuerySet(TranslatableQuerySet, TreeQuerySet):
pass
# Optional: make sure the Django 1.7 way of creating managers works.
def as_manager(cls):
# make sure creating managers from querysets works.
manager = CategoryManager.from_queryset(cls)()
manager._built_with_as_manager = True
return manager
Expand All @@ -74,15 +70,7 @@ so it needs to be redefined:
class CategoryManager(TreeManager, TranslatableManager):
queryset_class = CategoryQuerySet
def get_queryset(self):
# This is the safest way to combine both get_queryset() calls
# supporting all Django versions and MPTT 0.7.x versions
return self.queryset_class(self.model, using=self._db).order_by(self.tree_id_attr, self.left_attr)
if django.VERSION < (1,6):
get_query_set = get_queryset
_queryset_class = CategoryQuerySet
Assign the manager to the model ``objects`` attribute.
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
sys.path.insert(0, os.path.abspath('_ext'))
sys.path.insert(0, os.path.abspath('..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'djangodummy.settings'
if django.VERSION >= (1, 7):
django.setup()
django.setup()


# -- General configuration ------------------------------------------------
Expand Down
7 changes: 1 addition & 6 deletions example/article/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
from __future__ import unicode_literals
from django.db import models
from django.urls import reverse
from django.utils.encoding import python_2_unicode_compatible
from parler.models import TranslatableModel, TranslatedFields
from parler.utils.context import switch_language

try:
from django.urls import reverse
except ImportError:
# Django <= 1.10
from django.core.urlresolvers import reverse


@python_2_unicode_compatible
class Article(TranslatableModel):
Expand Down
15 changes: 1 addition & 14 deletions example/article/tests.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from collections import deque
from unittest import skipIf, expectedFailure

import django
from django.test.html import parse_html, Element
from django.test.utils import override_settings
from django.urls import reverse
from django.utils import encoding, translation
from django.test import TestCase
from django.contrib import auth
from .models import Article, Category
from parler.appsettings import PARLER_LANGUAGES

try:
from django.urls import reverse
except ImportError:
# Support for Django <= 1.10
from django.core.urlresolvers import reverse


class TestMixin(object):

Expand Down Expand Up @@ -79,8 +72,6 @@ def _is_dict_subset(d1, d2):


class ArticleTestCase(TestMixin, TestCase):
if django.VERSION < (1, 8):
urls = 'example.urls'

@override_settings(ROOT_URLCONF='example.urls')
def test_home(self):
Expand Down Expand Up @@ -128,7 +119,6 @@ def test_admin_list(self):
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed(resp, 'admin/change_list.html')

@skipIf(django.VERSION < (1, 5), "bug with declared_fieldsets in ArticleAdmin")
def test_admin_add(self):
self.client.login(**self.credentials)

Expand All @@ -153,7 +143,6 @@ def test_admin_add(self):
self.assertEqual(200, resp.status_code)
self.assertInContent('<h1>Add Article (Dutch)</h1>', resp)

@skipIf(django.VERSION < (1, 5), "bug with declared_fieldsets in ArticleAdmin")
def test_admin_add_post(self):
self.client.login(**self.credentials)
resp = self.client.post(
Expand All @@ -169,7 +158,6 @@ def test_admin_add_post(self):
self.assertRedirects(resp, reverse('admin:article_article_changelist'))
self.assertEqual(1, Article.objects.filter(translations__slug='my-article').count())

@skipIf(django.VERSION < (1, 5), "bug with declared_fieldsets in ArticleAdmin")
def test_admin_change(self):
self.client.login(**self.credentials)

Expand Down Expand Up @@ -255,7 +243,6 @@ def test_admin_delete_translation(self):
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed(resp, 'admin/parler/deletion_not_allowed.html')

@expectedFailure
def test_admin_delete_translation_unavailable(self):
"""
To be fixed : when trying to delete the last language when a translation
Expand Down
8 changes: 2 additions & 6 deletions example/example/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Django settings for example project.
import django
from os.path import join, dirname, realpath

SRC_DIR = dirname(dirname(realpath(__file__)))
Expand Down Expand Up @@ -63,16 +62,14 @@
]


MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware', # Inserted language switcher, easy way to have multiple frontend languages.
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
# Support Django >= 2.0
MIDDLEWARE = MIDDLEWARE_CLASSES

ROOT_URLCONF = 'example.urls'

Expand Down Expand Up @@ -117,8 +114,7 @@
}
}

if django.VERSION >= (1, 7):
TEST_RUNNER = 'django.test.runner.DiscoverRunner' # silence system checks
TEST_RUNNER = 'django.test.runner.DiscoverRunner' # silence system checks

PARLER_DEFAULT_LANGUAGE = 'en'

Expand Down
17 changes: 4 additions & 13 deletions example/example/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import django
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
Expand All @@ -8,15 +7,7 @@
# Patterns are prefixed with the language code.
# This is not mandatory, can also use a `django_language` cookie,
# or custom middleware that calls `django.utils.translation.activate()`.
if django.VERSION >= (1, 8):
# New style without prefix argument
urlpatterns = i18n_patterns(
url(r'^admin/', admin.site.urls),
url(r'', include('article.urls')),
)
else:
# Old style
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'', include('article.urls')),
)
urlpatterns = i18n_patterns(
url(r'^admin/', admin.site.urls),
url(r'', include('article.urls')),
)
Loading

0 comments on commit 4166a60

Please sign in to comment.