summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan <righiy90@gmail.com>2016-09-03 19:00:00 +0300
committerTim Graham <timograham@gmail.com>2016-09-03 12:00:00 -0400
commit9a2a52558e080f109a27d40a033a135c9d0e7e50 (patch)
tree256cb5ba46f97d795ecdcb3d6c79e772d5f12cee
parent277fe2e8f2ee35cd389b079ce7691491bb5738ec (diff)
downloaddjango-9a2a52558e080f109a27d40a033a135c9d0e7e50.tar.gz
Fixed #27171 -- Added unicode_literals and coding preamble to all files in startapp template on Python 2.
-rw-r--r--django/conf/app_template/admin.py-tpl2
-rw-r--r--django/conf/app_template/tests.py-tpl2
-rw-r--r--django/conf/app_template/views.py-tpl2
-rw-r--r--django/core/management/templates.py3
-rw-r--r--tests/admin_scripts/tests.py11
5 files changed, 15 insertions, 5 deletions
diff --git a/django/conf/app_template/admin.py-tpl b/django/conf/app_template/admin.py-tpl
index 8c38f3f3da..b2ff964e3b 100644
--- a/django/conf/app_template/admin.py-tpl
+++ b/django/conf/app_template/admin.py-tpl
@@ -1,3 +1,3 @@
-from django.contrib import admin
+{{ unicode_literals }}from django.contrib import admin
# Register your models here.
diff --git a/django/conf/app_template/tests.py-tpl b/django/conf/app_template/tests.py-tpl
index 7ce503c2dd..fa96c654d5 100644
--- a/django/conf/app_template/tests.py-tpl
+++ b/django/conf/app_template/tests.py-tpl
@@ -1,3 +1,3 @@
-from django.test import TestCase
+{{ unicode_literals }}from django.test import TestCase
# Create your tests here.
diff --git a/django/conf/app_template/views.py-tpl b/django/conf/app_template/views.py-tpl
index 91ea44a218..61821e705e 100644
--- a/django/conf/app_template/views.py-tpl
+++ b/django/conf/app_template/views.py-tpl
@@ -1,3 +1,3 @@
-from django.shortcuts import render
+{{ unicode_literals }}from django.shortcuts import render
# Create your views here.
diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index df522e809c..fd957fbabf 100644
--- a/django/core/management/templates.py
+++ b/django/core/management/templates.py
@@ -114,7 +114,8 @@ class TemplateCommand(BaseCommand):
camel_case_name: camel_case_value,
'docs_version': get_docs_version(),
'django_version': django.__version__,
- 'unicode_literals': '' if six.PY3 else 'from __future__ import unicode_literals\n\n',
+ 'unicode_literals': '' if six.PY3 else '# -*- coding: utf-8 -*-\n'
+ 'from __future__ import unicode_literals\n\n',
}), autoescape=False)
# Setup a stub settings environment for template rendering
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 1376ea9203..5ac24db6ea 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -613,7 +613,7 @@ 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"
+ unicode_literals_import = "# -*- coding: utf-8 -*-\nfrom __future__ import unicode_literals\n\n"
with open(os.path.join(app_path, 'apps.py'), 'r') as f:
content = f.read()
self.assertIn("class SettingsTestConfig(AppConfig)", content)
@@ -624,6 +624,15 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
with open(os.path.join(app_path, 'models.py'), 'r') as fp:
content = fp.read()
self.assertIn(unicode_literals_import, content)
+ with open(os.path.join(app_path, 'views.py'), 'r') as fp:
+ content = fp.read()
+ self.assertIn(unicode_literals_import, content)
+ with open(os.path.join(app_path, 'admin.py'), 'r') as fp:
+ content = fp.read()
+ self.assertIn(unicode_literals_import, content)
+ with open(os.path.join(app_path, 'tests.py'), 'r') as fp:
+ content = fp.read()
+ self.assertIn(unicode_literals_import, content)
def test_setup_environ_custom_template(self):
"directory: startapp creates the correct directory with a custom template"