Author: jezdez Date: 2012-02-04 05:01:30 -0800 (Sat, 04 Feb 2012) New Revision: 17432
Added: django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt Modified: django/trunk/django/core/management/templates.py django/trunk/docs/man/django-admin.1 django/trunk/docs/ref/django-admin.txt django/trunk/tests/regressiontests/admin_scripts/tests.py Log: Fixed #17517 -- Added `--name` option to startproject and startapp management commands to be able to render files without a file extension. Thanks, Florian Apolloner. Modified: django/trunk/django/core/management/templates.py =================================================================== --- django/trunk/django/core/management/templates.py 2012-02-04 12:48:21 UTC (rev 17431) +++ django/trunk/django/core/management/templates.py 2012-02-04 13:01:30 UTC (rev 17432) @@ -48,6 +48,11 @@ help='The file extension(s) to render (default: "py") ' 'Separate multiple extensions with commas, or use ' '-e multiple times.'), + make_option('--name', '-n', dest='files', + action='append', default=[], + help='The file name(s) to render ' + 'Separate multiple extensions with commas, or use ' + '-n multiple times.') ) requires_model_validation = False # Can't import settings during this command, because they haven't @@ -89,10 +94,16 @@ extensions = tuple( handle_extensions(options.get('extensions'), ignored=())) + extra_files = [] + for file in options.get('files'): + extra_files.extend(map(lambda x: x.strip(), file.split(','))) if self.verbosity >= 2: self.stdout.write("Rendering %s template files with " "extensions: %s\n" % (app_or_project, ', '.join(extensions))) + self.stdout.write("Rendering %s template files with " + "filenames: %s\n" % + (app_or_project, ', '.join(extra_files))) base_name = '%s_name' % app_or_project base_subdir = '%s_template' % app_or_project @@ -142,7 +153,7 @@ # accidentally render Django templates files with open(old_path, 'r') as template_file: content = template_file.read() - if filename.endswith(extensions): + if filename.endswith(extensions) or filename in extra_files: template = Template(content) content = template.render(context) with open(new_path, 'w') as new_file: Modified: django/trunk/docs/man/django-admin.1 =================================================================== --- django/trunk/docs/man/django-admin.1 2012-02-04 12:48:21 UTC (rev 17431) +++ django/trunk/docs/man/django-admin.1 2012-02-04 13:01:30 UTC (rev 17432) @@ -115,11 +115,11 @@ Prints the SQL statements for resetting PostgreSQL sequences for the given app name(s). .TP -.BI "startapp [" "\-\-template=PATH_OR_URL" "] [" "\-\-extension=EXTENSION" "] [" "appname" "] [" "destination" "]" +.BI "startapp [" "\-\-template=PATH_OR_URL" "] [" "\-\-extension=EXTENSION" "] [" "\-\-name=FILENAME" "] [" "appname" "] [" "destination" "]" Creates a Django app directory structure for the given app name in the current directory or the optional destination. .TP -.BI "startproject [" "\-\-template=PATH_OR_URL" "] [" "\-\-extension=EXTENSION" "] [" "projectname" "] [" "destination" "]" +.BI "startproject [" "\-\-template=PATH_OR_URL" "] [" "\-\-extension=EXTENSION" "] [" "\-\-name=FILENAME" "] [" "projectname" "] [" "destination" "]" Creates a Django project directory structure for the given project name in the current directory or the optional destination. .TP @@ -213,9 +213,12 @@ .I \-a, \-\-all Process all available locales when using makemessages..SH "ENVIRONMENT" .TP -.I \-a, \-\-template=PATH_OR_URL +.I \-\-template=PATH_OR_URL The file or directory path or URL to load the project and app templates from. .TP +.I \-n, \-\-name=FILENAME +The name of an additional file to render when using app and project templates. +.TP .I DJANGO_SETTINGS_MODULE In the absence of the .BI \-\-settings Modified: django/trunk/docs/ref/django-admin.txt =================================================================== --- django/trunk/docs/ref/django-admin.txt 2012-02-04 12:48:21 UTC (rev 17431) +++ django/trunk/docs/ref/django-admin.txt 2012-02-04 13:01:30 UTC (rev 17432) @@ -951,7 +951,8 @@ When Django copies the app template files, it also renders the files whose extension matches those passed with the ``--extension`` option (``py`` -by default) using the template engine. The :class:`template context +by default) and those files which names are passed with the ``--name`` option +using the template engine. The :class:`template context <django.template.Context>` used is: - Any option passed to the startapp command @@ -1013,7 +1014,8 @@ When Django copies the project template files, it will also render the files whose extension matches those passed with the ``--extension`` option (``py`` -by default) using the template engine. The :class:`template context +by default) and those files which names are passed with the ``--name`` option +using the template engine. The :class:`template context <django.template.Context>` used is: - Any option passed to the startproject command Added: django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile =================================================================== --- django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile (rev 0) +++ django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/Procfile 2012-02-04 13:01:30 UTC (rev 17432) @@ -0,0 +1 @@ +# some file for {{ project_name }} test project \ No newline at end of file Added: django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt =================================================================== --- django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt (rev 0) +++ django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/additional_dir/requirements.txt 2012-02-04 13:01:30 UTC (rev 17432) @@ -0,0 +1 @@ +# some file for {{ project_name }} test project \ No newline at end of file Modified: django/trunk/tests/regressiontests/admin_scripts/tests.py =================================================================== --- django/trunk/tests/regressiontests/admin_scripts/tests.py 2012-02-04 12:48:21 UTC (rev 17431) +++ django/trunk/tests/regressiontests/admin_scripts/tests.py 2012-02-04 13:01:30 UTC (rev 17432) @@ -1489,3 +1489,21 @@ self.assertNoOutput(err) self.assertTrue(os.path.isdir(testproject_dir)) self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py'))) + + def test_file_without_extension(self): + "Make sure the startproject management command is able to render custom files" + template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') + args = ['startproject', '--template', template_path, 'customtestproject', '-e', 'txt', '-n', 'Procfile'] + testproject_dir = os.path.join(test_dir, 'customtestproject') + + out, err = self.run_django_admin(args) + self.addCleanup(shutil.rmtree, testproject_dir) + self.assertNoOutput(err) + self.assertTrue(os.path.isdir(testproject_dir)) + self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'additional_dir'))) + base_path = os.path.join(testproject_dir, 'additional_dir') + for f in ('Procfile', 'additional_file.py', 'requirements.txt'): + self.assertTrue(os.path.exists(os.path.join(base_path, f))) + with open(os.path.join(base_path, f)) as fh: + self.assertEqual(fh.read(), + '# some file for customtestproject test project') -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.