Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17920 -- Actually pass the full path of a newly created projec…

…t or app in the template context as mentioned in the startproject docs. Many thanks to Preston Holmes for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17773 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4219e2b7f833171bd24c6dd9802deb9eb7d0bafe 1 parent 1101739
Jannis Leidel authored March 21, 2012
3  django/conf/project_template/manage.py
... ...
@@ -1,5 +1,6 @@
1 1
 #!/usr/bin/env python
2  
-import os, sys
  2
+import os
  3
+import sys
3 4
 
4 5
 if __name__ == "__main__":
5 6
     os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
6  django/core/management/templates.py
@@ -89,8 +89,10 @@ def handle(self, app_or_project, name, target=None, **options):
89 89
                     message = e
90 90
                 raise CommandError(message)
91 91
         else:
92  
-            top_dir = path.expanduser(target)
93  
-
  92
+            top_dir = os.path.abspath(path.expanduser(target))
  93
+            if not os.path.exists(top_dir):
  94
+                raise CommandError("Destination directory '%s' does not "
  95
+                                   "exist, please create it first." % top_dir)
94 96
 
95 97
         extensions = tuple(
96 98
             handle_extensions(options.get('extensions'), ignored=()))
7  tests/regressiontests/admin_scripts/custom_templates/project_template/manage.py
... ...
@@ -1 +1,6 @@
1  
-# The manage.py of the {{ project_name }} test project
  1
+# The manage.py of the {{ project_name }} test project
  2
+
  3
+# template context:
  4
+project_name = '{{ project_name }}'
  5
+project_directory = '{{ project_directory }}'
  6
+secret_key = '{{ secret_key }}'
29  tests/regressiontests/admin_scripts/tests.py
@@ -1534,3 +1534,32 @@ def test_file_without_extension(self):
1534 1534
             with open(os.path.join(base_path, f)) as fh:
1535 1535
                 self.assertEqual(fh.read(),
1536 1536
                     '# some file for customtestproject test project')
  1537
+
  1538
+    def test_custom_project_template_context_variables(self):
  1539
+        "Make sure template context variables are rendered with proper values"
  1540
+        template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template')
  1541
+        args = ['startproject', '--template', template_path, 'another_project', 'project_dir']
  1542
+        testproject_dir = os.path.join(test_dir, 'project_dir')
  1543
+        os.mkdir(testproject_dir)
  1544
+        out, err = self.run_django_admin(args)
  1545
+        self.addCleanup(shutil.rmtree, testproject_dir)
  1546
+        self.assertNoOutput(err)
  1547
+        test_manage_py = os.path.join(testproject_dir, 'manage.py')
  1548
+        with open(test_manage_py, 'r') as fp:
  1549
+            content = fp.read()
  1550
+            self.assertIn("project_name = 'another_project'", content)
  1551
+            self.assertIn("project_directory = '%s'" % testproject_dir, content)
  1552
+
  1553
+    def test_custom_project_destination_missing(self):
  1554
+        """
  1555
+        Make sure an exception is raised when the provided
  1556
+        destination directory doesn't exist
  1557
+        """
  1558
+        template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template')
  1559
+        args = ['startproject', '--template', template_path, 'yet_another_project', 'project_dir2']
  1560
+        testproject_dir = os.path.join(test_dir, 'project_dir2')
  1561
+        out, err = self.run_django_admin(args)
  1562
+        self.assertNoOutput(out)
  1563
+        self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir)
  1564
+        self.assertFalse(os.path.exists(testproject_dir))
  1565
+

0 notes on commit 4219e2b

Please sign in to comment.
Something went wrong with that request. Please try again.