From 10427646b887586bf89dacb3b5208b3ad2d17308 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 10 Dec 2015 09:13:05 -0500 Subject: [PATCH] Fixed #25909 -- Added unicode_literals import to apps.py generated by startapp. --- django/conf/app_template/apps.py | 2 +- docs/releases/1.9.1.txt | 5 +++++ tests/admin_scripts/tests.py | 8 ++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/django/conf/app_template/apps.py b/django/conf/app_template/apps.py index 9b2ce5289c..8d1a017751 100644 --- a/django/conf/app_template/apps.py +++ b/django/conf/app_template/apps.py @@ -1,4 +1,4 @@ -from django.apps import AppConfig +{{ unicode_literals }}from django.apps import AppConfig class {{ camel_case_app_name }}Config(AppConfig): diff --git a/docs/releases/1.9.1.txt b/docs/releases/1.9.1.txt index 60b793f3e9..bc4a0be8ad 100644 --- a/docs/releases/1.9.1.txt +++ b/docs/releases/1.9.1.txt @@ -29,3 +29,8 @@ Bugfixes * Fixed admin's delete confirmation page's summary counts of related objects (:ticket:`25883`). + +* Added ``from __future__ import unicode_literals`` to the default ``apps.py`` + created by ``startapp`` on Python 2 (:ticket:`25909`). Add this line to your + own ``apps.py`` files created using Django 1.9 if you want your migrations + to work on both Python 2 and Python 3. diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 755fb0b1d4..ea7c8a25f0 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -610,17 +610,17 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase): self.addCleanup(shutil.rmtree, app_path) self.assertNoOutput(err) self.assertTrue(os.path.exists(app_path)) + unicode_literals_import = "from __future__ import unicode_literals\n" with open(os.path.join(app_path, 'apps.py'), 'r') as f: content = f.read() self.assertIn("class SettingsTestConfig(AppConfig)", content) self.assertIn("name = 'settings_test'", content) + if not PY3: + self.assertIn(unicode_literals_import, content) if not PY3: with open(os.path.join(app_path, 'models.py'), 'r') as fp: content = fp.read() - self.assertIn( - "from __future__ import unicode_literals\n", - content, - ) + self.assertIn(unicode_literals_import, content) def test_setup_environ_custom_template(self): "directory: startapp creates the correct directory with a custom template"