Ticket #17517: 17517-2.diff
File 17517-2.diff, 5.8 KB (added by , 13 years ago) |
---|
-
django/core/management/templates.py
diff --git a/django/core/management/templates.py b/django/core/management/templates.py index 0a6a3a8..1d26e97 100644
a b class TemplateCommand(BaseCommand): 48 48 help='The file extension(s) to render (default: "py") ' 49 49 'Separate multiple extensions with commas, or use ' 50 50 '-e multiple times.'), 51 make_option('--name', '-n', dest='files', 52 action='append', default=[], 53 help='The file name(s) to render ' 54 'Separate multiple extensions with commas, or use ' 55 '-n multiple times.') 51 56 ) 52 57 requires_model_validation = False 53 58 # Can't import settings during this command, because they haven't … … class TemplateCommand(BaseCommand): 89 94 90 95 extensions = tuple( 91 96 handle_extensions(options.get('extensions'), ignored=())) 97 extra_files = [] 98 for file in options.get('files'): 99 extra_files.extend(map(lambda x: x.strip(), file.split(','))) 92 100 if self.verbosity >= 2: 93 101 self.stdout.write("Rendering %s template files with " 94 102 "extensions: %s\n" % 95 103 (app_or_project, ', '.join(extensions))) 104 self.stdout.write("Rendering %s template files with " 105 "filenames: %s\n" % 106 (app_or_project, ', '.join(extra_files))) 96 107 97 108 base_name = '%s_name' % app_or_project 98 109 base_subdir = '%s_template' % app_or_project … … class TemplateCommand(BaseCommand): 142 153 # accidentally render Django templates files 143 154 with open(old_path, 'r') as template_file: 144 155 content = template_file.read() 145 if filename.endswith(extensions) :156 if filename.endswith(extensions) or filename in extra_files: 146 157 template = Template(content) 147 158 content = template.render(context) 148 159 with open(new_path, 'w') as new_file: -
docs/ref/django-admin.txt
diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index 4bde86c..a44bcff 100644
a b creating the ``myapp`` app:: 951 951 952 952 When Django copies the app template files, it also renders the files 953 953 whose extension matches those passed with the ``--extension`` option (``py`` 954 by default) using the template engine. The :class:`template context 954 by default) and those files which names are passed with the ``--name`` option 955 using the template engine. The :class:`template context 955 956 <django.template.Context>` used is: 956 957 957 958 - Any option passed to the startapp command … … when creating the ``myproject`` project:: 1013 1014 1014 1015 When Django copies the project template files, it will also render the files 1015 1016 whose extension matches those passed with the ``--extension`` option (``py`` 1016 by default) using the template engine. The :class:`template context 1017 by default) and those files which names are passed with the ``--name`` option 1018 using the template engine. The :class:`template context 1017 1019 <django.template.Context>` used is: 1018 1020 1019 1021 - Any option passed to the startproject command -
new file tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile
diff --git a/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile b/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile new file mode 100644 index 0000000..032f0bc
- + 1 # some file for {{ project_name }} test project 2 No newline at end of file -
new file tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt
diff --git a/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt b/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt new file mode 100644 index 0000000..032f0bc
- + 1 # some file for {{ project_name }} test project 2 No newline at end of file -
tests/regressiontests/admin_scripts/tests.py
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index 17a2ccb..3939825 100644
a b class StartProject(LiveServerTestCase, AdminScriptTestCase): 1489 1489 self.assertNoOutput(err) 1490 1490 self.assertTrue(os.path.isdir(testproject_dir)) 1491 1491 self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py'))) 1492 1493 def test_custom_project_template(self): 1494 "Make sure the startproject management command is able to render custom files" 1495 template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') 1496 args = ['startproject', '--template', template_path, 'customtestproject', '-e', 'txt', '-n', 'Procfile'] 1497 testproject_dir = os.path.join(test_dir, 'customtestproject') 1498 1499 out, err = self.run_django_admin(args) 1500 self.addCleanup(shutil.rmtree, testproject_dir) 1501 self.assertNoOutput(err) 1502 self.assertTrue(os.path.isdir(testproject_dir)) 1503 self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'additional_dir'))) 1504 base_path = os.path.join(testproject_dir, 'additional_dir') 1505 for f in ('Procfile', 'additional_file.py', 'requirements.txt'): 1506 self.assertTrue(os.path.exists(os.path.join(base_path, f))) 1507 with open(os.path.join(base_path, f)) as fh: 1508 self.assertEqual(fh.read(), 1509 '# some file for customtestproject test project')