1 import os |
1 import os |
2 |
2 |
3 from django.core.management.base import copy_helper, CommandError, LabelCommand |
3 from django.core.management.base import copy_helper, CommandError, LabelCommand |
4 |
4 |
5 class Command(LabelCommand): |
5 class Command(LabelCommand): |
6 help = ("Creates a Django app directory structure for the given app name" |
6 help = "Creates a Django app directory structure for the given app name in the current directory." |
7 " in the current directory.") |
|
8 args = "[appname]" |
7 args = "[appname]" |
9 label = 'application name' |
8 label = 'application name' |
10 |
9 |
11 requires_model_validation = False |
10 requires_model_validation = False |
12 # Can't import settings during this command, because they haven't |
11 # Can't import settings during this command, because they haven't |
14 can_import_settings = False |
13 can_import_settings = False |
15 |
14 |
16 def handle_label(self, app_name, directory=None, **options): |
15 def handle_label(self, app_name, directory=None, **options): |
17 if directory is None: |
16 if directory is None: |
18 directory = os.getcwd() |
17 directory = os.getcwd() |
|
18 |
19 # Determine the project_name by using the basename of directory, |
19 # Determine the project_name by using the basename of directory, |
20 # which should be the full path of the project directory (or the |
20 # which should be the full path of the project directory (or the |
21 # current directory if no directory was passed). |
21 # current directory if no directory was passed). |
22 project_name = os.path.basename(directory) |
22 project_name = os.path.basename(directory) |
23 if app_name == project_name: |
23 if app_name == project_name: |
24 raise CommandError("You cannot create an app with the same name" |
24 raise CommandError("You cannot create an app with the same name" |
25 " (%r) as your project." % app_name) |
25 " (%r) as your project." % app_name) |
|
26 |
|
27 # Check that the app_name cannot be imported. |
|
28 try: |
|
29 __import__(app_name) |
|
30 except ImportError: |
|
31 pass |
|
32 else: |
|
33 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) |
|
34 |
26 copy_helper(self.style, 'app', app_name, directory, project_name) |
35 copy_helper(self.style, 'app', app_name, directory, project_name) |
27 |
36 |
28 class ProjectCommand(Command): |
37 class ProjectCommand(Command): |
29 help = ("Creates a Django app directory structure for the given app name" |
38 help = ("Creates a Django app directory structure for the given app name" |
30 " in this project's directory.") |
39 " in this project's directory.") |