Author: jezdez
Date: 2012-03-21 15:29:32 -0700 (Wed, 21 Mar 2012)
New Revision: 17773
Modified:
django/trunk/django/conf/project_template/manage.py
django/trunk/django/core/management/templates.py
django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/manage.py
django/trunk/tests/regressiontests/admin_scripts/tests.py
Log:
Fixed #17920 -- Actually pass the full path of a newly created project or app
in the template context as mentioned in the startproject docs. Many thanks to
Preston Holmes for the initial patch.
Modified: django/trunk/django/conf/project_template/manage.py
===================================================================
--- django/trunk/django/conf/project_template/manage.py 2012-03-21 05:57:22 UTC
(rev 17772)
+++ django/trunk/django/conf/project_template/manage.py 2012-03-21 22:29:32 UTC
(rev 17773)
@@ -1,5 +1,6 @@
#!/usr/bin/env python
-import os, sys
+import os
+import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name
}}.settings")
Modified: django/trunk/django/core/management/templates.py
===================================================================
--- django/trunk/django/core/management/templates.py 2012-03-21 05:57:22 UTC
(rev 17772)
+++ django/trunk/django/core/management/templates.py 2012-03-21 22:29:32 UTC
(rev 17773)
@@ -89,9 +89,11 @@
message = e
raise CommandError(message)
else:
- top_dir = path.expanduser(target)
+ top_dir = os.path.abspath(path.expanduser(target))
+ if not os.path.exists(top_dir):
+ raise CommandError("Destination directory '%s' does not "
+ "exist, please create it first." % top_dir)
-
extensions = tuple(
handle_extensions(options.get('extensions'), ignored=()))
extra_files = []
Modified:
django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/manage.py
===================================================================
---
django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/manage.py
2012-03-21 05:57:22 UTC (rev 17772)
+++
django/trunk/tests/regressiontests/admin_scripts/custom_templates/project_template/manage.py
2012-03-21 22:29:32 UTC (rev 17773)
@@ -1 +1,6 @@
-# The manage.py of the {{ project_name }} test project
\ No newline at end of file
+# The manage.py of the {{ project_name }} test project
+
+# template context:
+project_name = '{{ project_name }}'
+project_directory = '{{ project_directory }}'
+secret_key = '{{ secret_key }}'
Modified: django/trunk/tests/regressiontests/admin_scripts/tests.py
===================================================================
--- django/trunk/tests/regressiontests/admin_scripts/tests.py 2012-03-21
05:57:22 UTC (rev 17772)
+++ django/trunk/tests/regressiontests/admin_scripts/tests.py 2012-03-21
22:29:32 UTC (rev 17773)
@@ -1534,3 +1534,32 @@
with open(os.path.join(base_path, f)) as fh:
self.assertEqual(fh.read(),
'# some file for customtestproject test project')
+
+ def test_custom_project_template_context_variables(self):
+ "Make sure template context variables are rendered with proper values"
+ template_path = os.path.join(test_dir, 'admin_scripts',
'custom_templates', 'project_template')
+ args = ['startproject', '--template', template_path,
'another_project', 'project_dir']
+ testproject_dir = os.path.join(test_dir, 'project_dir')
+ os.mkdir(testproject_dir)
+ out, err = self.run_django_admin(args)
+ self.addCleanup(shutil.rmtree, testproject_dir)
+ self.assertNoOutput(err)
+ test_manage_py = os.path.join(testproject_dir, 'manage.py')
+ with open(test_manage_py, 'r') as fp:
+ content = fp.read()
+ self.assertIn("project_name = 'another_project'", content)
+ self.assertIn("project_directory = '%s'" % testproject_dir,
content)
+
+ def test_custom_project_destination_missing(self):
+ """
+ Make sure an exception is raised when the provided
+ destination directory doesn't exist
+ """
+ template_path = os.path.join(test_dir, 'admin_scripts',
'custom_templates', 'project_template')
+ args = ['startproject', '--template', template_path,
'yet_another_project', 'project_dir2']
+ testproject_dir = os.path.join(test_dir, 'project_dir2')
+ out, err = self.run_django_admin(args)
+ self.assertNoOutput(out)
+ self.assertOutput(err, "Destination directory '%s' does not exist,
please create it first." % testproject_dir)
+ self.assertFalse(os.path.exists(testproject_dir))
+
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.