app/django/core/management/commands/startapp.py
changeset 54 03e267d67478
child 323 ff1a9aa48cfd
equal deleted inserted replaced
53:57b4279d8c4e 54:03e267d67478
       
     1 import os
       
     2 
       
     3 from django.core.management.base import copy_helper, CommandError, LabelCommand
       
     4 
       
     5 class Command(LabelCommand):
       
     6     help = ("Creates a Django app directory structure for the given app name"
       
     7             " in the current directory.")
       
     8     args = "[appname]"
       
     9     label = 'application name'
       
    10 
       
    11     requires_model_validation = False
       
    12     # Can't import settings during this command, because they haven't
       
    13     # necessarily been created.
       
    14     can_import_settings = False
       
    15 
       
    16     def handle_label(self, app_name, directory=None, **options):
       
    17         if directory is None:
       
    18             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)
       
    26         copy_helper(self.style, 'app', app_name, directory, project_name)
       
    27 
       
    28 class ProjectCommand(Command):
       
    29     help = ("Creates a Django app directory structure for the given app name"
       
    30             " in this project's directory.")
       
    31 
       
    32     def __init__(self, project_directory):
       
    33         super(ProjectCommand, self).__init__()
       
    34         self.project_directory = project_directory
       
    35 
       
    36     def handle_label(self, app_name, **options):
       
    37         super(ProjectCommand, self).handle_label(app_name, self.project_directory, **options)