3
from django.core.management.base import copy_helper, CommandError, LabelCommand
5
class Command(LabelCommand):
6
help = "Creates a Django app directory structure for the given app name in the current directory."
8
label = 'application name'
10
requires_model_validation = False
11
# Can't import settings during this command, because they haven't
12
# necessarily been created.
13
can_import_settings = False
15
def handle_label(self, app_name, directory=None, **options):
17
directory = os.getcwd()
19
# Determine the project_name by using the basename of directory,
20
# which should be the full path of the project directory (or the
21
# current directory if no directory was passed).
22
project_name = os.path.basename(directory)
23
if app_name == project_name:
24
raise CommandError("You cannot create an app with the same name"
25
" (%r) as your project." % app_name)
27
# Check that the app_name cannot be imported.
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)
35
copy_helper(self.style, 'app', app_name, directory, project_name)
37
class ProjectCommand(Command):
38
help = ("Creates a Django app directory structure for the given app name"
39
" in this project's directory.")
41
def __init__(self, project_directory):
42
super(ProjectCommand, self).__init__()
43
self.project_directory = project_directory
45
def handle_label(self, app_name, **options):
46
super(ProjectCommand, self).handle_label(app_name, self.project_directory, **options)