Code

Ticket #15515: django-15515.diff

File django-15515.diff, 4.0 KB (added by Joshua "jag" Ginsberg <jag@…>, 3 years ago)
Line 
1diff -r 86ae13d9baaf -r 302c8b593c9d django/core/management/base.py
2--- a/django/core/management/base.py
3+++ b/django/core/management/base.py
4@@ -357,7 +357,8 @@
5         """
6         raise NotImplementedError()
7 
8-def copy_helper(style, app_or_project, name, directory, other_name=''):
9+def copy_helper(style, app_or_project, name, directory, other_name='',
10+                template_dir=None):
11     """
12     Copies either a Django application layout template or a Django project
13     layout template into the specified directory.
14@@ -385,10 +386,11 @@
15     except OSError, e:
16         raise CommandError(e)
17 
18-    # Determine where the app or project templates are. Use
19-    # django.__path__[0] because we don't know into which directory
20-    # django has been installed.
21-    template_dir = os.path.join(django.__path__[0], 'conf', '%s_template' % app_or_project)
22+    if not template_dir:
23+        # Determine where the app or project templates are. Use
24+        # django.__path__[0] because we don't know into which directory
25+        # django has been installed.
26+        template_dir = os.path.join(django.__path__[0], 'conf', '%s_template' % app_or_project)
27 
28     for d, subdirs, files in os.walk(template_dir):
29         relative_dir = d[len(template_dir)+1:].replace('%s_name' % app_or_project, name)
30diff -r 86ae13d9baaf -r 302c8b593c9d django/core/management/commands/startapp.py
31--- a/django/core/management/commands/startapp.py
32+++ b/django/core/management/commands/startapp.py
33@@ -1,5 +1,5 @@
34 import os
35-
36+from optparse import make_option
37 from django.core.management.base import copy_helper, CommandError, LabelCommand
38 from django.utils.importlib import import_module
39 
40@@ -8,6 +8,14 @@
41     args = "[appname]"
42     label = 'application name'
43 
44+    option_list = LabelCommand.option_list + (
45+        make_option('--template',
46+                    action='store',
47+                    dest='template_dir',
48+                    default=None,
49+                    help='Path to a custom project template'),
50+        )
51+
52     requires_model_validation = False
53     # Can't import settings during this command, because they haven't
54     # necessarily been created.
55@@ -33,7 +41,8 @@
56         else:
57             raise CommandError("%r conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name." % app_name)
58 
59-        copy_helper(self.style, 'app', app_name, directory, project_name)
60+        copy_helper(self.style, 'app', app_name, directory, project_name,
61+                    template_dir=options['template_dir'])
62 
63 class ProjectCommand(Command):
64     help = ("Creates a Django app directory structure for the given app name"
65diff -r 86ae13d9baaf -r 302c8b593c9d django/core/management/commands/startproject.py
66--- a/django/core/management/commands/startproject.py
67+++ b/django/core/management/commands/startproject.py
68@@ -2,6 +2,7 @@
69 from django.utils.importlib import import_module
70 import os
71 import re
72+from optparse import make_option
73 from random import choice
74 
75 class Command(LabelCommand):
76@@ -9,6 +10,14 @@
77     args = "[projectname]"
78     label = 'project name'
79 
80+    option_list = LabelCommand.option_list + (
81+        make_option('--template',
82+                    action='store',
83+                    dest='template_dir',
84+                    default=None,
85+                    help='Path to a custom project template'),
86+        )
87+
88     requires_model_validation = False
89     # Can't import settings during this command, because they haven't
90     # necessarily been created.
91@@ -27,7 +36,8 @@
92         else:
93             raise CommandError("%r conflicts with the name of an existing Python module and cannot be used as a project name. Please try another name." % project_name)
94 
95-        copy_helper(self.style, 'project', project_name, directory)
96+        copy_helper(self.style, 'project', project_name, directory,
97+                    template_dir=options['template_dir'])
98 
99         # Create a random SECRET_KEY hash, and put it in the main settings.
100         main_settings_file = os.path.join(directory, project_name, 'settings.py')